Jid*_*ide 30 javascript jquery jquery-ui
我想创建一个可排序小部件的自定义版本.我一直在寻找文档,但找不到真正准确的东西.我找到的最好的信息是:http://jqueryui.pbworks.com/Widget-factory.
我试过了 :
$.widget("ui.customsortable", $.extend($.ui.sortable, {
_init: function() {
$.widget.prototype._init.apply(this, arguments);
}
}));
Run Code Online (Sandbox Code Playgroud)
但$ .widget.prototype._init不是我想调用的函数我猜是因为它是$ .widget原型.
然后,我尝试了我在这里和那里读到的东西:
var _init = $.ui.sortable.prototype._init;
$.widget("ui.customsortable", $.extend($.ui.sortable, {
_init: function() {
_init.apply(this, arguments);
},
}));
Run Code Online (Sandbox Code Playgroud)
但是:
我在这里错过了什么吗?
谢谢你的帮助 !
bul*_*are 28
这些都是有点奇怪的答案.有一个可选的第二个参数 - 要继承的basewidget.这很简单.无需使用原型等.
$.widget( "ui.customsortable", $.ui.sortable, {
_init: function() {
this.element.data('sortable', this.element.data('customsortable'));
// or whatever you want
}
} );
Run Code Online (Sandbox Code Playgroud)
第二个参数是$ .ui.sortable.我认为这就是你所需要的.
Jid*_*ide 22
经过几次尝试,我终于找到了如何轻松完成这项工作:
$.widget("ui.customsortable", $.extend({}, $.ui.sortable.prototype, {
_init: function(){
this.element.data('sortable', this.element.data('customsortable'));
return $.ui.sortable.prototype._init.apply(this, arguments);
}
// Override other methods here.
}));
$.ui.customsortable.defaults = $.extend({}, $.ui.sortable.defaults);
Run Code Online (Sandbox Code Playgroud)
关键是将数据从自定义窗口小部件复制到原始窗口小部件.不要忘记使用$ .ui.sortable.prototype.[overriden method] .apply(this,arguments); 在每个覆盖方法中.
天哪 !
| 归档时间: |
|
| 查看次数: |
17340 次 |
| 最近记录: |