Jquery ui 使用Solr缓存自动完成
我正在使用jQueryUI和Solr创建一个自动完成的整洁搜索框。该查询似乎运行良好,但结果实际上并未显示在“我的搜索”框中。以下是我正在使用的代码:Jquery ui 使用Solr缓存自动完成,jquery-ui,solr,Jquery Ui,Solr,我正在使用jQueryUI和Solr创建一个自动完成的整洁搜索框。该查询似乎运行良好,但结果实际上并未显示在“我的搜索”框中。以下是我正在使用的代码: var cache = {}; $("#Keyword").autocomplete({ minLength: 3, source: function(request, response) { var term = request.term; if(term in cache) {
var cache = {};
$("#Keyword").autocomplete({
minLength: 3,
source: function(request, response) {
var term = request.term;
if(term in cache) {
response(cache[term]);
return;
}
$.getJSON("http://127.0.0.1:8080/solr/terms/?terms=true&terms.fl=ctnt_val&wt=json&indent=on&terms.prefix=" + $("#Keyword").val(),
request,
function(data, status, xhr) {
cache[term] = data;
response(data);
});
}
});
所以我最好的猜测是我没有正确处理返回的值。如何使它们正确地显示在搜索框下面?我能够确定返回函数中的错误:我没有正确地循环搜索结果。最好的方法是使用map函数对它们进行迭代
$("#Keyword").autocomplete({
minLength: 3,
source: function(request, response) {
$query = "http://127.0.0.1:8080/solr/terms/?jsoncallback=?&terms=true&terms.prefix=" + $("#Keyword").val();
$.getJSON($query,
request,
function(data) {
response($.map(data.terms.ctnt_val, function(item) {
return item;
}));
}
);
}
});