我升级到Bootstrap 3.0版,我确实看到了typeahead模块不存在。我正在使用Web服务,我使用以下方法调用我的函数并填充我的数据集。但是,使用twitter typeahead.js,如何调用我的函数或如何使用旧的typeahead模块?非常感谢您的帮助。感谢。
$("#searchVendor").typeahead({
source: function (query) {
vieModel.callWebServiceFunctionList(counter1, query, isListCleared);
});
答案 0 :(得分:0)
Typeahead.js无法直接将函数用作source
。传递查询值的标准方法是使用%QUERY
属性中包含remote
的URL字符串:
$("#searchVendor").typeahead({
remote: '.../data.json?name=%QUERY'
});
但是,在您的情况下,这可能还不够。 remote
也可以是一个对象,其中url
和replace
函数应用于该网址。
因此,创建一个像callWebServiceFunctionList
这样只返回URL而不是实际调用Web服务的函数。
$("#searchVendor").typeahead({
remote: {
url: '.../data.json?counter=%COUNTER&query=%QUERY&isListCleared=%ISLISTCLEARED',
replace: function(url, query) {
return url.replace('%COUNTER', counter1).replace('%QUERY', query).replace('%ISLISTCLEARED', isListCleared);
}
});
对于remote
对象,
或者,您可以只获取Bootstrap 2.x的typeahead部分的JS,虽然您可能会遇到格式化问题,it seems to work fine by itself(JSFiddle演示)。