所以我搜索但找不到答案.这可能是微不足道的,但我无法看到导致这种情况的原因.
我正在使用jQuery UI Autocomplete,它显示了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 });
解决方法
必须根据“Term”参数在服务器端执行过滤.检查服务器使用Firebug或Chrome开发人员工具返回的数据(F12),并确保它取决于“term”参数.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。