2011-01-25 80 views
6

下面這個簡單的代碼描述了我的問題(至少我hopse左右):繼承jQuery UI的對話框,並調用覆蓋的方法

$.widget("ui.mydialog", $.ui.dialog, { 
    _create: function() { 
    // How to call _create method of dialog? 
    } 
}); 

席力圖召$.ui.dialog.prototype._create()從內上述create方法,但得到以下錯誤在Firebug:

this.element is undefined 
this.originalTitle = this.element.attr('title'); 
jquery...5667348 (line 5864) 

我怎麼能稱之爲「超級」方法?

jQuery UI的版本1.8.8

回答

11

我想我只是找到了一個解決方案... $.ui.dialog.prototype._create.call(this);

的完整代碼:

$.widget("ui.ajaxdialog", $.ui.dialog, { 
    _create: function() { 
    // Your code before calling the overridden method. 
    $.ui.dialog.prototype._create.call(this); 
    // Your code after calling the overridden method. 
    } 
}); 
+6

對於jQueryUI的1.9倍,你可以簡單地做:`這._super('_ create');`上面的解決方案也是有效的。 – earcam 2012-07-20 13:24:23