gpt4 book ai didi

jquery - 扩展 jQuery UI 小部件时,如何扩展多个功能?

转载 作者:行者123 更新时间:2023-12-01 04:19:38 25 4
gpt4 key购买 nike

我目前正在扩展 jQuery UI 小部件,如下所示:

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});
}
});

这工作正常,但我现在想扩展另一个函数,如下所示:

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});
}

_response: function(contents){
$.ui.autocomplete.prototype._response.apply(this, arguments);
$(this.element).trigger("autocompletesearchcomplete", [contents]);
}

});

不幸的是这个错误,如上所示扩展多个功能的正确方法是什么?

谢谢

最佳答案

我认为缺少逗号

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
_renderMenu: function( ul, items ) {
var self = this,
currentCategory = "";
$.each( items, function( index, item ) {
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
self._renderItem( ul, item );
});

}, // <--- you're missing this comma

_response: function(contents){
$.ui.autocomplete.prototype._response.apply(this, arguments);
$(this.element).trigger("autocompletesearchcomplete", [contents]);
}

});

关于jquery - 扩展 jQuery UI 小部件时,如何扩展多个功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12047057/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com