追加一个项目一个jQuery用户界面自动完成

问题描述:

目前,我使用的是引用一个ASHX文件的文本框jQuery用户界面自动完成。

Currently, I'm using jQuery UI autocomplete on a textbox that references an ASHX file.

一切工作propertly,但我想在读取列表的末尾追加项目:找不到项目按此要求添加一个新的项目。

Everything is working propertly, except I want to append an item at the end of the list that reads: "Item not found? Click here to request to add a new item."

我试过code以下的线,但是它所作的只是格式项目的,我无法追加。

I tried the following the lines of code, but all it did was format the item's, I was unable to append.

data( "catcomplete" )._renderItem = function( ul, item ) {
        return $( "<li></li>" )
            .data( "item.catcomplete", item )
            .append( $( "<a class='ui-menu-item'></a>" ).text( item.label ) )
            .appendTo( $('ul').last('.autocomplete-category'));
    };

提示?提示? MUCHO格拉西亚斯! :D

Hints? Tips? Mucho gracias! :D

您应该在 添加额外的条目打开事件火灾。这会给你访问到列表中,这是你所追求的,而不是每一个元素,这是你获得什么 _renderItem 所赐。

下面是一个例子造型已经被填充到列表中的条目:

Here's an example styling the entries that have been populated into the list:

$("#myBox").autocomplete({
        source: "[URL]",
        minLength: 2,
        open: function(event, ui) {
            $("ul.ui-autocomplete.ui-menu .ui-menu-item:odd").css("background-color","#dedede");
        }
    });