我有下面的代碼,如果我使用2.0.0版本,肯定會返回正確的數據結果,但由於某些原因bootstrap的typeahead插件給我一個錯誤。我粘貼它的代碼示例如下:twitter引導typeahead 2.0.4 ajax錯誤
<input id="test" type="text" />
$('#test').typeahead({
source: function(typeahead, query) {
return $.post('/Profile/searchFor', { query: query }, function(data) {
return typeahead.process(data);
});
}
});
當我運行這個例子中,我得到一個jQuery的錯誤,說以下內容:
**
item is undefined
matcher(item=undefined)bootst...head.js (line 104)
<br/>(?)(item=undefined)bootst...head.js (line 91)
<br/>f(a=function(), b=function(), c=false)jquery....min.js (line 2)
<br/>lookup(event=undefined)bootst...head.js (line 90)
<br/>keyup(e=Object { originalEvent=Event keyup, type="keyup", timeStamp=145718131, more...})bootst...head.js (line 198)
<br/>f()jquery....min.js (line 2)
<br/>add(c=Object { originalEvent=Event keyup, type="keyup", timeStamp=145718131, <br/>more...})jquery....min.js (line 3)
<br/>add(a=keyup charCode=0, keyCode=70)jquery....min.js (line 3)
<br/>[Break On This Error]
<br/>return item.toLowerCase().indexOf(this.query.toLowerCase())**
有什麼想法? ...相同的代碼在2.0.0版本的插件中工作,但未能寫入我的挖空對象模型。
這是工作預輸入代碼,版本2.0.0:
var searchFunction = function(typeahead, query) {
$.ajax({
url: "/Profile/searchFor?tableName=" + tableName + "&query=" + query + "&extendedData=" + $("#" + extendedData).val(),
success: function(data) {
if (data.errorText != null) {
toggleLoading("false");
showDialog(data.errorText, "Error");
return;
}
var result = data.results.split("::");
typeahead.process(result);
},
select: function(event, ui) {
}
});
}
$("#" + inputBoxId).typeahead({
source: searchFunction,
onselect: function(obj) {
}
});
什麼是完整的錯誤請 – Esailija
在原始文章中添加了更多信息。 –
在Bootstrap typeahead'source'必須是一個數組。 http://twitter.github.com/bootstrap/javascript.html#typeahead – Esailija