[英]Bootstrap3 Typeahead - Calling a function in 'Remote'
I upgraded to Bootstrap version 3.0 and I do see that the typeahead module does not exist. 我已升级到Bootstrap 3.0版,但确实看到不存在typeahead模块。 I am using web services and I had used the following method to call my function and populate my dataset. 我正在使用Web服务,并且已经使用以下方法调用函数并填充数据集。 However, with the twitter typeahead.js, how do I call my function or how do I still use the old typeahead module? 但是,使用twitter typeahead.js,如何调用函数或仍然使用旧的typeahead模块? Your help is much appreciated. 非常感谢您的帮助。 Thanks. 谢谢。
$("#searchVendor").typeahead({
source: function (query) {
vieModel.callWebServiceFunctionList(counter1, query, isListCleared);
});
Typeahead.js doesn't have a way of directly using a function as the source
. Typeahead.js无法直接使用函数作为source
。 The standard way to pass a query value is with a URL string containing %QUERY
in the remote
property: 传递查询值的标准方法是在remote
属性中使用包含%QUERY
的URL字符串:
$("#searchVendor").typeahead({
remote: '.../data.json?name=%QUERY'
});
However, this probably isn't enough in your case. 但是,这可能还不够。 remote
can also be an object, with a url
and a replace
function that is applied to the URL. remote
也可以是一个对象,具有url
和应用于URL的replace
功能。
So, make a function like callWebServiceFunctionList
that just returns the URL instead of actually calling the web service. 因此,使像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);
}
});
See the docs for the remote
object. 请参阅文档以获取remote
对象。
Alternatively, you could get the JS for just the typeahead portion of Bootstrap 2.x, and while you might run into problems with the formatting, it seems to work fine by itself (JSFiddle demo). 或者,您可以只为Bootstrap 2.x的typeahead部分获得JS,尽管您可能会遇到格式问题, 但它似乎可以正常工作 (JSFiddle演示)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.