使用 JQuery UI 自动完成显示不显示结果

发布于 2024-11-26 11:19:50 字数 883 浏览 6 评论 0原文

我正在使用 Jquery UI 的自动完成功能,并且可以在 Firebug 中看到返回的正确 JSON 数据。但是,文本框中没有任何内容。

我的 JavaScript:

$(function() {
        function log( message ) {
            $( "<div/>" ).text( message ).prependTo( "#log" );

        }

        $("#tags").autocomplete({
        source: function(request, response){
                    $.ajax ({
                url: "/projectlist",
                                dataType: "json",
                                data: {style: "full", maxRows: 12, term: request.term}
                            });
                                            }

    })
});

您可以从代码片段中看到正在返回 JSON 数据。但结果表中没有显示任何内容。它应该类似于 JQuery 自动完成示例 JQuery 自动完成

浏览器在 firebug 中返回的内容的片段

I'm using Jquery UI's autocomplete, and I can see the proper JSON data coming back in Firebug. However, nothing's coming back to the textbox.

My JavaScript:

$(function() {
        function log( message ) {
            $( "<div/>" ).text( message ).prependTo( "#log" );

        }

        $("#tags").autocomplete({
        source: function(request, response){
                    $.ajax ({
                url: "/projectlist",
                                dataType: "json",
                                data: {style: "full", maxRows: 12, term: request.term}
                            });
                                            }

    })
});

You can see that from the snippet JSON data is being returned. But nothing is being displayed in the results table. Which should look like the the JQuery autocomplete example JQuery Autocomplete

Snippet of what browser returns in firebug

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-12-03 11:19:50

显示 Noyhing 是因为您没有返回任何内容,我认为:您必须将成功函数添加到您的 ajax 调用中(我添加了成功响应的示例,如果您告诉我们您的 json 是如何构造的,我可以更好地帮助您。无论如何,您必须返回一个对象数组,每个对象应该有一个名为“label”的属性和一个名为“value”的属性:

$("#tags").autocomplete({
    source: function(request, response) {
        $.ajax({
            url: "/projectlist",
            dataType: "json",
            data: {
                style: "full",
                maxRows: 12,
                term: request.term
            },
            success: function(data) {
                var results = [];
                $.each(data, function(i, item) {
                    var itemToAdd = {
                        value: item,
                        label: item
                    };
                    results.push(itemToAdd);
                });
                return response(results);

            }
        });
    }
});

我在这里设置了一个小提琴:http://jsfiddle.net/nicolapeluchetti/pRzTy/ (假设“data”是返回的 json )

Noyhing is displayed because you return nothing i think: you must add e success function to your ajax call (i added an example of a success response, if you tell us how your json is tructured i could help you better. in any case you must return an array of objects, and each object should have a property named 'label' and one named 'value':

$("#tags").autocomplete({
    source: function(request, response) {
        $.ajax({
            url: "/projectlist",
            dataType: "json",
            data: {
                style: "full",
                maxRows: 12,
                term: request.term
            },
            success: function(data) {
                var results = [];
                $.each(data, function(i, item) {
                    var itemToAdd = {
                        value: item,
                        label: item
                    };
                    results.push(itemToAdd);
                });
                return response(results);

            }
        });
    }
});

I set up a fiddle here: http://jsfiddle.net/nicolapeluchetti/pRzTy/ (imagine that 'data' is the json that is returned)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文