I'm using jqueryUI's widget factory to extend jqUI's dialog widget. I've setup the simplest widget I can think of. It does nothing, just inherits from dialog. Still I've not been able to get it to work.
I have a fiddle demonstrating it here: View Fiddle
Here's the test markup:
<div id="a">hello</div>
<div id="b">bye</div>
Here's the javascript:
(function ($, undefined)
{
var o = //Widget prototype
{
options: {},
_create: function () {},
destroy: function ()
{
$.Widget.prototype.destroy.call(this);
},
_setOption: function (key, value)
开发者_高级运维 {
$.Widget.prototype._setOption.apply(this, arguments);
},
};
//Run jQuery's widget factory to create the widget
$.widget('cs.csDialog', $.ui.dialog, o);
} (jQuery));
//Test it out
$("#a").dialog(); //Works
$("#b").csDialog(); //Fails
Inside jqUI I get the following error: this.uiDialog is undefined
I can't see what I've done wrong. I'd greatly appreciate any help. Thank you.
The reason it is not working, as I wrote in my comment, is because you overwrote the _create function.
Just for future readers, here is how to call the base _create function as mentioned in the comments. Answered inspired by William Niu answer for a different question.
_create: function() {
$.ui.dialog.prototype._create.call(this);
}
Another way to call the base _create is to add the following line of code in your method:
this._super();
精彩评论