4
我需要自定義jquery ui控件。我只想改變「創建」方法。 我寫了一個從ui.automplete小部件繼承的新小部件。 這工作正常。但是,如何添加新的事件,如選擇,點擊,更改? 不可能在小部件繼承上添加事件嗎?jQuery ui控件繼承
$.widget("ui.my_autocomplete", $.ui.autocomplete, {
_create: function() {
//Here is my customized code
},
select: function(event, ui) { // Not working!
console.log("-- test my_autocomplete select: ");
ui.item.option.selected = true;
.....
},
change: function(event, ui) { // Not working!
console.log("-- test my_autocomplete change: ");
.....
}
});
jQuery UI的1.8 ui.automplete方法:
$.widget("ui.autocomplete", {
options: {
minLength: 1,
delay: 300
},
_create: function() {
...
},
destroy: function() {
...
},
_setOption: function(key) {
...
},
_initSource: function() {
...
},
search: function(value, event) {
...
},
_search: function(value) {
...
},
_response: function(content) {
...
},
close: function(event) {
...
},
_normalize: function(items) {
...
},
_suggest: function(items) {
...
},
_renderMenu: function(ul, items) {
...
},
_renderItem: function(ul, item) {
...
},
_move: function(direction, event) {
...
},
widget: function() {
...
}
});
我試圖在窗口小部件中實現繼承,但像Uncaught TypeError一樣的錯誤:我不是構造函數即將到來。請你看看這個問題 http://stackoverflow.com/questions/39009882/how-to-implement-inheritance-in-jquery-ui-widget – Arun