【问题标题】:jQuery UI Autocomplete Not Filtering DatajQuery UI 自动完成不过滤数据
【发布时间】:2012-02-09 05:43:57
【问题描述】:

所以我搜索但找不到答案。这可能是微不足道的事情,但我就是看不出是什么原因造成的。

我正在使用 jQuery UI 自动完成,它显示 json 结果。所以我知道我的 JSON 是有效的。但是,它没有过滤任何东西。所以我可以输入一个数字,它只显示所有数据。任何提示将不胜感激!

感谢您的宝贵时间!

这是我的自动完成代码。

    $.widget('custom.catcomplete', $.ui.autocomplete, {
    _renderMenu: function(ul, items) {
        var self = this,
            currentCategory = '';
        $.each(items, function(index, item) {
            if (item.category != currentCategory) {
                ul.append('<li class="ui-autocomplete-category">' + item.category + '</li>');
                currentCategory = item.category;
            }
            self._renderItem(ul, item);
        });
    }
   });


   $('#category').catcomplete({
    source: function(request, response) {
        $.ajax({
            url: '/wp-content/plugins/pagelines-sections/searchbar/products.json',
            dataType: 'json',
            data: {
                term: request.term
            },
            cache: true,
            success: function(data) {
                response($.map(data.products, function(item) {
                    return {
                        category: item.category,
                        label: item.label,
                        value: item.value
                    };
                }));
            }
        });
       },
       minLength: 1
   });

【问题讨论】:

    标签: jquery json filtering jquery-ui-autocomplete


    【解决方案1】:

    在这篇文章中完成了关于 JQuery UI 自动完成组件的解释 :)

    Jquery UI AutoComplete

    【讨论】:

      【解决方案2】:

      过滤必须在服务器端执行,基于“Term”参数。使用 Firebug 或 Chrome 开发人员工具 (F12) 检查您的服务器返回的数据,并确保它取决于“term”参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-05
        • 1970-01-01
        • 2020-07-02
        • 1970-01-01
        • 2023-03-13
        • 2011-02-21
        • 1970-01-01
        相关资源
        最近更新 更多