Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 使用Solr缓存自动完成_Jquery Ui_Solr - Fatal编程技术网

Jquery ui 使用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) {

我正在使用jQueryUI和Solr创建一个自动完成的整洁搜索框。该查询似乎运行良好,但结果实际上并未显示在“我的搜索”框中。以下是我正在使用的代码:

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;
                }));
            }
        );
    }
});