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

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

问题描述

这答案 - <一个href=\"http://stackoverflow.com/questions/2435964/jqueryui-how-can-i-custom-format-the-autocomplete-plug-in-results/2436493#2436493\">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?

当我检查 $('$输入')。自动完成,我没有看到任何的自动完成FNS那里(_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/

Here's a working demo: http://jsfiddle.net/vJSwq/

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

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