如何在页面上修补*一个*自动完成实例? [英] How to patch *just one* instance of Autocomplete on a page?

查看:20
本文介绍了如何在页面上修补*一个*自动完成实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个答案——jQueryUI:如何自定义自动完成插件结果的格式? -- 描述如何对 jqueryUI 自动完成小部件进行猴子补丁,以便它以特定方式显示内容.它使用的方法是替换 $.ui.autocomplete.prototype 上的一个函数.

This answer -- jQueryUI: how can I custom-format the Autocomplete plug-in results? -- describes how to monkeypatch the jqueryUI autocomplete widget, so that it displays things in a particular way. The approach it uses is to replace a function on the $.ui.autocomplete.prototype.

这意味着所有自动完成小部件都将获得此补丁.

This means that all autocomplete widgets will get this patch.

有没有办法为仅一个输入元素修补自动完成小部件?它是什么?

Is there a way to patch the autocomplete widget for just one input element? What is it?

当我检查 $('$input').autocomplete 时,我在那里没有看到任何自动完成功能(_renderItem、_renderMenu、_search 等).

When I examine $('$input').autocomplete , I don't see any of the autocomplete fns there (_renderItem, _renderMenu, _search, etc).

推荐答案

查看自定义数据并显示演示.这个演示没有修改自动完成小部件的原型对象,这意味着只有小部件的那个实例受到影响:

Check out the custom data and display demo. This demo is not modifying the prototype object of the autocomplete widget, meaning that only that instance of the widget is effected:

$("selector").autocomplete({ ... }).data( "autocomplete" )._renderItem = function( ul, item ) {
    return $( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
        .appendTo( ul );
};

这是一个工作演示:http://jsfiddle.net/vJSwq/

这篇关于如何在页面上修补*一个*自动完成实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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