多个元素的 jQuery UI 自动完成格式 [英] jQuery UI Autocomplete Formatting for Multiple Elements
问题描述
我根据自己的喜好设置了 jQuery UI 自动完成设置并且运行良好,但是有一个致命的缺陷.在我的自动完成中,我使用自定义显示像这个例子.我有一些非常相似的东西,但有一个例外......
I have the jQuery UI Autocomplete setup to my liking and working perfectly, but there is one fatal flaw. In my autocomplete I use a custom display like this example. I have something very similar built but with on exception...
唯一的区别是我在那个页面上有多个同一个类的自动完成元素.只有第一个元素显示额外的数据行,其余只显示基本的自动完成.
The only difference is that I have multiple autocomplete elements of the same class on that one page. Only the first element shows the extra data line, the rest only show the basic autocomplete.
我可以通过迭代所有这些类元素并在它们上调用自动完成来获得所需的结果,但我希望有一种更好的方法来调用它并让它正常工作".
I can get the desired result by just iterating all of those class elements and calling the autocomplete on them, but I was hoping there was a better way of calling it once and having it "just work".
这是我添加额外行的方法:
Here's how I'm adding the extra line:
.data( 'autocomplete' )._renderItem = function( ul, item ) {
return $( '<li></li>' )
.data( 'item.autocomplete', item )
.append( '<a>' + item.label + '<br/><small>' + item.desc + '<small></a>' )
.appendTo( ul );
};
我应该注意,我根本没有收到任何控制台异常.
I should note that I'm not getting any console exceptions at all.
推荐答案
我能完成这项工作的唯一方法是更改我的代码:
The only way I can make this work is by changing my code from:
addautocomplete($('.tagEntry'));
致:
$('.tagEntry').each(function() {
addautocomplete(this);
});
这篇关于多个元素的 jQuery UI 自动完成格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!