我正在使用 $.widget 工厂扩展一个 jQuery UI 小部件。在这种特殊情况下,我继承了 Wijmo 的 wijlinechart。我需要从我的孩子班级中响应 wijlinechart 的“绘制”事件。
考虑一下:
$.widget("bw.wijlinechartcursor", $.wijmo.wijlinechart, {
_create: function () {
var self = this;
$.wijmo.wijlinechart.prototype._create.apply(self, arguments);
self.element.on("painted", function (e) {
alert("Got painted in child via element.on"); // Doesn't get called.
});
// This works, but blows away the client code's handler (below)
self.options.painted = function (e) {
alert("Got painted in child class via options.painted!");
}
},
_painted: function () {
alert("Got painted in child via _painted"); // Doesn't get called.
}
});
$("#mywijlinechartcursor").wijlinechartcursor({
// ... stuff...
painted: function (e) {
alert("Got painted in client code");
}
});
那么,在由继承的父类触发的子类中处理事件的最有效方法是什么?