Javascript 自动完成-自定义渲染/菜单和项目选择问题

Javascript 自动完成-自定义渲染/菜单和项目选择问题,javascript,jquery,ajax,jquery-ui,autocomplete,Javascript,Jquery,Ajax,Jquery Ui,Autocomplete,我将jQueryUI(1.10.2)和jQuery(1.9.1)与自动完成工具一起使用 我有远程json数据和类别以及自定义显示,其中包含json数据中每个项目的图像(显示在自动完成列表中) 这是我的自动完成初始化 var autoSearch = $("#header-search-text").autocomplete({ source: function( request, response ) { $.ajax({ //I have ite

我将jQueryUI(1.10.2)和jQuery(1.9.1)与自动完成工具一起使用

我有远程json数据和类别以及自定义显示,其中包含json数据中每个项目的图像(显示在自动完成列表中)

这是我的自动完成初始化

var autoSearch = $("#header-search-text").autocomplete({
    source: function( request, response ) {
        $.ajax({
            //I have items with label, value, category and imgPath info
        });
    },
     focus: function( event, ui ) {
        console.log("focus is ");
        //This line shows "null"
        console.log(ui);
        return false;
    },
    minLength: 4,
    select: function( event, ui ) {
        //Never shows up
        console.log("selected is ");
        console.log( ui.item);/* ?
        "Selected: " + ui.item.label :
        "Nothing selected, input was " + this.value);*/
    },
    open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
    },
    close: function() {
        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
    }
}).data('ui-autocomplete');
我有一个自定义的渲染菜单

//Working
autoSearch._renderMenu = function( ul, items ) {
        var that = this,
        currentCategory = "";
        $.each( items, function( index, item ) {
            console.log(item);
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            that._renderItem( ul, item );
        });
};
//正在工作
自动搜索。\u renderMenu=功能(ul,项目){
var=这个,
currentCategory=“”;
$。每个(项目、功能(索引、项目){
控制台日志(项目);
如果(item.category!=当前类别){
ul.追加(“
  • ”+item.category+“
  • ”); currentCategory=item.category; } 即._renderItem(ul,项目); }); };
    但是当我有了_renderItem时,选择的键(上下)不再起作用,我不能点击任何东西(否:出现悬停CSS)

    autoSearch.\u renderItem=功能(ul,项目){
    控制台日志(“ul is”);
    控制台日志(ul);
    返回$(“
  • ”) .data('item.autocomplete',item) .append(“”+项.标签) .附录(ul); };
  • 好的,我检查了HTML,很明显,我在_renderItem中遗漏了这一行:

     //Before the appendTo(ul);
    .append( $( "<a>" ).text( item.label ) )
    

    好的,我检查了HTML,很明显我在_renderItem中遗漏了这一行:

     //Before the appendTo(ul);
    .append( $( "<a>" ).text( item.label ) )
    
    “添加一个”是什么意思?我看起来需要一个标记,否则它不会在菜单中添加其他内容。刷新“添加一个”是什么意思?我看起来需要一个标记,否则它不会在菜单中添加其他内容。刷新
    id="ui-id-7" class="ui-corner-all" tabindex="-1"