我正在编写一个jqueryui小部件,我希望在小部件更改时使用_trigger获取一些小部件数据。我使用小部件如下:
$("#myDiv").myWidget({
change: function(e) {
alert($("#filter").myWidget('getWidgetData'));
// do something with the widget data.
}
});
此代码有效(当窗口小部件调用_trigger时,警报将触发并显示窗口小部件数据)。但是,这是获取更改回调内部窗口小部件数据的正确/最佳方法吗?对于isntance,我似乎无法调用this.getWidgetData或e.getWidgetData。
答案 0 :(得分:1)
您可以将数据附加到触发的更改事件中。你应该有类似的东西:
this._trigger('change', e);
并且可以使用:
this._trigger('change', e, { widgetData: this.getWidgetData() });
_trigger
函数接受A hash of data associated with the event.
作为documentation中描述的第三个arg。
您的代码将变为:
$("#myDiv").myWidget({
change: function(e, data) {
alert(data.widgetData);
// do something with the widget data.
}
});