admin管理员组文章数量:1328014
I am using the Bootstrap-3 Typeahead plugin as well as the Bootstrap Tag Input plugin. I use it like this:
<input type="text" id="name" name="test" data-provide="typeahead">
And the jQuery:
$.get('/design/assets/advertisements/countries.json', function(data) {
$("#name").typeahead({
source: data
});
$('#name').tagsinput({
typeahead: {
source: data
}
});
}, 'json');
However, the typeahead and tags works to some point. Whenever I enter some words, i get suggestions, but whenever I've selected a suggestion, whatever I was writing will be added after the tag input.
Example: If I write "Bah
" and select "Bahamas
", it looks like this: (Where I would believe that it would delete the "Bah")
I get this error - I don't know if that's the reason:
Uncaught TypeError: Cannot read property 'name' of undefined
The error is called to this file: bootstrap3-typeahead.js
I am using the Bootstrap-3 Typeahead plugin as well as the Bootstrap Tag Input plugin. I use it like this:
<input type="text" id="name" name="test" data-provide="typeahead">
And the jQuery:
$.get('/design/assets/advertisements/countries.json', function(data) {
$("#name").typeahead({
source: data
});
$('#name').tagsinput({
typeahead: {
source: data
}
});
}, 'json');
However, the typeahead and tags works to some point. Whenever I enter some words, i get suggestions, but whenever I've selected a suggestion, whatever I was writing will be added after the tag input.
Example: If I write "Bah
" and select "Bahamas
", it looks like this: (Where I would believe that it would delete the "Bah")
I get this error - I don't know if that's the reason:
Uncaught TypeError: Cannot read property 'name' of undefined
The error is called to this file: bootstrap3-typeahead.js
- check this stackoverflow./questions/29360584/… – Dhiraj Commented Jun 30, 2015 at 2:46
2 Answers
Reset to default 6I've downloaded non-min version of bootstrap-3 typeahead plugin and changed this:
displayText: function(item) {
return item.name || item;
},
to this
displayText: function(item) {
if (typeof item == 'undefined') {
return '';
}
return item.name || item;
},
It solved the problem.
Actually I don't know whether it's a bootstrap-3 typeahead plugin bug or some kind of it's inpatibility with bootstrap tags input plugin which I use.
I did the following change for Bootstrap 3 - typeahead in line number 312
Old Code:
displayText: function (item) {
return typeof item !== 'undefined' && typeof item.name != 'undefined' && item.name || item;
},
Updated Code:
displayText: function (item) {
if(item){
if(item.name){
return item.name;
}
return item;
}
else{
return '';
}
},
版权声明:本文标题:javascript - jQuery Typeahead - Uncaught TypeError: Cannot read property 'name' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742245038a2439074.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论