[英]How can i get remote call on bootstrap twitter typeahead to work, by calling asp.net web method
[英]Bootstrap3 Typeahead - Calling a function in 'Remote'
我已升级到Bootstrap 3.0版,但确实看到不存在typeahead模块。 我正在使用Web服务,并且已经使用以下方法调用函数并填充数据集。 但是,使用twitter typeahead.js,如何调用函数或仍然使用旧的typeahead模块? 非常感谢您的帮助。 谢谢。
$("#searchVendor").typeahead({
source: function (query) {
vieModel.callWebServiceFunctionList(counter1, query, isListCleared);
});
Typeahead.js无法直接使用函数作为source
。 传递查询值的标准方法是在remote
属性中使用包含%QUERY
的URL字符串:
$("#searchVendor").typeahead({
remote: '.../data.json?name=%QUERY'
});
但是,这可能还不够。 remote
也可以是一个对象,具有url
和应用于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,尽管您可能会遇到格式问题, 但它似乎可以正常工作 (JSFiddle演示)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.