jQuery UI的自动完成格式化多个元素 [英] jQuery UI Autocomplete Formatting for Multiple Elements

查看:157
本文介绍了jQuery UI的自动完成格式化多个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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.

推荐答案

我可以使这项工作的唯一方法是通过改变我的code:

The only way I can make this work is by changing my code from:

addautocomplete($('.tagEntry'));

要:

$('.tagEntry').each(function() {
     addautocomplete(this);
});

这篇关于jQuery UI的自动完成格式化多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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