【发布时间】:2012-06-24 15:03:50
【问题描述】:
如果我使用 2.0.0 版本,我有以下代码肯定会返回正确的数据结果,但由于某种原因,引导程序的 typeahead 插件给了我一个错误。我将其粘贴在代码示例下方:
<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) {
}
});
【问题讨论】:
-
请问完整的错误是什么
-
在原帖中添加了更多信息。
-
在 Bootstrap 中预先输入
source必须是一个数组。 twitter.github.com/bootstrap/javascript.html#typeahead -
这在
2.0.0中也行不通:github.com/twitter/bootstrap/blob/… 在代码中只有一个地方使用了source,作为$.grep的参数。 -
bootstrap typeahead 仅适用于文档甚至源代码所示的简单数组...您必须使用 jQuery UI 自动完成或其他方式。
标签: ajax twitter-bootstrap typeahead