微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有类别的jQuery UI自动完成

我正在使用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'

它没有任何暗示.这是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 );

这再次有效!

原文地址:https://www.jb51.cc/jquery/177304.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐