将项目附加到 jQuery UI 自动完成 [英] Appending an item to a jQuery UI autocomplete

查看:25
本文介绍了将项目附加到 jQuery UI 自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我在引用 ASHX 文件的文本框上使用 jQuery UI 自动完成功能.

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

一切正常,除了我想在列表末尾附加一个项目,上面写着:找不到项目?单击此处请求添加新项目."

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."

我尝试了以下代码行,但它所做的只是格式化项目,我无法追加.

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'));
    };

提示?提示?多谢!:D

Hints? Tips? Mucho gracias! :D

推荐答案

你应该在 Open 事件 触发.这将使您能够访问列表,这是您所追求的,而不是每个元素,这是 _renderItem 允许您访问的内容.

You should add your extra entry after the Open event fires. That will give you access to the list, which is what you are after, rather than to each element, which is what the _renderItem is giving you access to.

以下是对已填充到列表中的条目进行样式设置的示例:

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");
        }
    });

这篇关于将项目附加到 jQuery UI 自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆