对于要在_destroy UI Widget中实现哪个jQuery或destroy方法,我有点困惑。
在这个MSDN Widget引用中,它说要实现destroy(),但是在这个教程+引用中,它说要实现_destroy()。
两个引用都指出,这些方法应该将元素返回到它的预小部件状态。所以我理解这个部分,但是为什么小部件工厂中有两个版本的这个方法呢?
发布于 2013-04-08 18:18:23
从jQuery UI中读取文档,而不是在MSDN上读取
http://wiki.jqueryui.com/w/page/12138135/Widget%20factory
// Use the destroy method to clean up any modifications your widget has made to the DOM
destroy: function() {
// In jQuery UI 1.8, you must invoke the destroy method from the base widget
$.Widget.prototype.destroy.call( this );
// In jQuery UI 1.9 and above, you would define _destroy instead of destroy and not call the base method
}});
发布于 2014-06-18 14:29:40
只是为了澄清(并基于这):
在jQuery UI 1.8中,您的小部件应该如下所示:
$.widget( "demo.widget", {
destroy: function() {
// Invoke the base destroy method
$.Widget.prototype.destroy.call( this );
// Perform widget-specific cleanup
...
}
});在jQuery UI 1.9中,如下所示:
$.widget( "demo.widget", {
_destroy: function() {
// Perform widget-specific cleanup
...
}
});也就是说,在1.9中,您不应该定义(public) destroy方法;而是定义_destroy;并且在其中不需要调用基本调用析构函数。
https://stackoverflow.com/questions/15886043
复制相似问题