2015-06-29 27 views
3

我正在使用Bootstrap-3 Typeahead plugin以及Bootstrap Tag Input plugin。我用这样的:jQuery Typeahead - 未捕获TypeError:无法读取未定义的属性“名称”

<input type="text" id="name" name="test" data-provide="typeahead"> 

而jQuery的:

$.get('/design/assets/advertisements/countries.json', function(data) { 
    $("#name").typeahead({ 
     source: data 
    }); 
    $('#name').tagsinput({ 
     typeahead: { 
      source: data 
     } 
    }); 
}, 'json'); 

然而,预输入和标签工作的一些点。每当我输入一些单词时,我都会收到建议,但每当我选择一个建议时,我所写的任何内容都会在标签输入后添加。

例子:如果我写“Bah”,然后选择“Bahamas”,它看起来像这样:(这里我会相信它会删除“呸”)

enter image description here

我得到这个错误 - 我不知道如果是这样的原因:

Uncaught TypeError: Cannot read property 'name' of undefined 

的误差调用这个文件:bootstrap3-typeahead.js

+0

检查此问题http://stackoverflow.com/questions/29360584/twitter-bootstrap-3-typeahead-tagsinput-completing-twice – Dhiraj

回答

5

我已经下载了非分钟版本的引导-3预输入插件,改变了这一点:

displayText: function(item) { 
    return item.name || item; 
}, 

这个

displayText: function(item) { 
    if (typeof item == 'undefined') { 
    return ''; 
    } 
    return item.name || item; 
}, 

它解决了这个问题。

其实我不知道它是一个bootstrap-3 typeahead插件错误还是某种它与我使用的bootstrap标签输入插件不兼容。

相关问题