【发布时间】:2012-10-18 07:03:44
【问题描述】:
我正在使用jquery autocomplete with multiple results and a remote datasource。我能够远程提取数据并选择多个结果。 但结果列表不会根据输入的前 2 个字符更新,并且 jQueryUI 文档在这个问题上很薄。
我进行了研究,并在 SO 上找到了this answer,并希望将其与我的其他功能集成,但它不会更新结果列表。独立地,SO 答案可以正常工作,但在与多个结果和远程数据源集成时就不行了。
来自自动完成/远程源/多重功能(截断)。这部分工作正常:
.autocomplete({
source: function( request, response ) {
$.ajax({
url: "/controller/myfunction",
dataType: "json",
data: request,
success: function(data){
if(data.response == 'true') {
response(data.message);
}
}
});
},
Possible solution on SO:(独立工作正常,但不适用于 jquery/remote/multiple 代码):
var wordlist= [ "about", "above", "within", "without"];
$("#input1").autocomplete({
source: function(req, responseFn) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp( "^" + re, "i" );
var a = $.grep( wordlist, function(item,index){
return matcher.test(item);
});
responseFn( a );
}
});
我需要将此解决方案与我的代码集成。
【问题讨论】:
-
您可以在服务器上过滤您的结果吗?这样您甚至不必担心在 JS 中进行过滤。
-
@AndrewWhitaker - 那将是理想的;我正在研究这两种选择,并试图看看哪一种最先结出果实。
标签: jquery jquery-ui jquery-ui-autocomplete