我被困在jQuery 1.7和jQueryUI 1.8.6上,目前無法升級(我們有相當多的已棄用和刪除的代碼,並且無法在此時升級) 。舊版本的jQueryUI中的類別AutoComplete控件
我可以使用jQueryUI's AutoComplete control,但我無法弄清楚如何使用類別 - 使用樣本found here。
$.widget("custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)");
},
_renderMenu: function(ul, items) {
var that = this,
currentCategory = "";
$.each(items, function(index, item) {
var li;
if (item.category != currentCategory) {
ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
currentCategory = item.category;
}
li = that._renderItemData(ul, item);
if (item.category) {
li.attr("aria-label", item.category + " : " + item.label);
}
});
}
});
我得到一個錯誤:this._super is not a function
,如果我刪除了這一行,然後調用widget()
時,與Cannot read property 'element' of undefined
以下行失敗。
我知道jQuery插件的語法在版本之間有所變化,但我似乎無法修改它們的示例,以便它可以與舊版本一起使用。 This question在1.7中暗示了一個稍微不同的語法,但是當我弄亂它時,我只是不斷收到不同的錯誤。
任何想法,我需要改變,使這項工作?
完美,非常感謝。你保存了一天。 –