它会在找到的第一个自动完成中正确覆盖,但对其余部分不执行任何操作。 相反,它会加载原始的 _renderitem 方法,您可以在 https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.autocomplete.js#L449 中看到该方法。 。
$(".someClassWithMultipleItemsOnDOM").autocomplete({
delay:500,
minLength:2,
source:path"
.....
}).data( "autocomplete" )._renderItem = function( ul, item ) {
提前致谢
最佳答案
此问题有一个解决方法:
var autoc = {
delay: 500,
minLength: 2,
source: path,
.....
};
var renderItem = function (ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "<br/>" + item.desc + "</a>")
.appendTo(ul);
};
$(".someClassWithMultipleItemsOnDOM").each(function (i) {
$(this).autocomplete(autoc).data("autocomplete")._renderItem = renderItem;
}
关于jquery - 无法多次重写 jQuery UI 自动完成 renderItem 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7180246/