问题描述
我尝试根据(UI版本1.8.16)扩展UI对话框:
I try to extend UI dialog according to documentation (UI version 1.8.16):
(function($) {
$.widget('ui.mydialog', $.extend(true, $.ui.dialog.prototype, {
_create: function() {
return $.Widget.prototype._create.apply(this, arguments);
}
}));
})(jQuery);
$(function() {
$('div#dialog').mydialog();
});
执行此代码会导致JS错误:this.uiDialog is undefined。
Executing of this code causes JS error: "this.uiDialog is undefined".
如果尝试覆盖_init()方法没有错误,但父方法调用不起作用。
And if try to override the _init() method there are no errors, but parent method call takes no effect.
我'混淆..对于例如延伸哪种方式是合法的把一些自定义初始化代码?
I'm confused.. Which way is legal to extending for e.g. put some custom initialize code?
推荐答案
我认为这篇文章可以解决你的问题:。
I think this post would solve your question: Inherit from jQuery UI dialog and call overridden method.
简而言之,如果你想构建一个继承jQuery UI Dialog的小部件,你可以这样做:
In short, if you want to build a widget inheriting jQuery UI Dialog, you can do this:
(function($) {
$.widget("ui.mydialog", $.ui.dialog, {
_create: function() {
$.ui.dialog.prototype._create.call(this);
}
});
})(jQuery);
请参阅此操作:。
本教程将启发您:。简而言之, $。小部件
是基本小部件对象。即使它有 _create
函数,它默认也不做任何事情,将初始化代码留给子类。看一下这个更新的例子: http://jsfiddle.net/william/RELxP/1。
This tutorial will enlighten you: http://wiki.jqueryui.com/w/page/12138135/Widget%20factory. In short, $.Widget
is the base widget object. Even though it has a _create
function, it by default does nothing, leaving the initialisation code to the subclass. Take a look at this updated example: http://jsfiddle.net/william/RELxP/1.
这篇关于使用重新定义的父方法在Jquery UI中扩展窗口小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!