我正在使用jQuery UI的自动完成功能来从远程源提供搜索输入框的建议.我有“远程数据源”示例正常工作.例如,这有效:
$("#search").autocomplete({ source: "search_basic.PHP",minLength: 2 });
但是,我想使用“Categories”示例按类别对建议进行排序.来自jQuery UI站点的示例,带有内联数据集可以正常工作:
<script> $.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 ); }); } }); $(function() { var data = [ { label: "anders",category: "" },{ label: "andreas",{ label: "antal",{ label: "annhhx10",category: "Products" },{ label: "annk K12",{ label: "annttop C13",{ label: "anders andeRSSon",category: "People" },{ label: "andreas andeRSSon",{ label: "andreas johnson",category: "People" } ]; $( "#search" ).catcomplete({ delay: 0,source: data }); }); </script>
source: 'search.PHP'
<script> $.widget( "custom.catcomplete",item ); }); } }); $(function() { $( "#search" ).catcomplete({ source: 'search.PHP' }); }); </script>
search.PHP返回的数据格式正确:
[ { label: "annhhx10",{ label: "annttop",{ label: "anders",category: "People" } ]
任何帮助将不胜感激!
谢谢,
格雷格
解决方法
自从我迁移到UI 1.10.2后,我的小部件无法正常工作!
只是对该行的修改:
self._renderItem( ul,item );
变为:
self._renderItemData( ul,item );
这再次有效!