在窗口小部件事件处理程序中时,如何访问窗口小部件选项中保存的数据 [英] Howto access data held in widget options when inside a widget event handler

查看:100
本文介绍了在窗口小部件事件处理程序中时,如何访问窗口小部件选项中保存的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据保存在options变量中,但是在选择列表的事件中(OnChange) 这是指DOMElement,因此this.options是指对象列表.

I have data held in the options variable, but in an event (OnChange) of a select list this refers to the DOMElement and therefore this.options refers to the list of objects.

我在其他任何地方可以拥有

everywhere else I can have

var o = this.options;

但这在这种情况下是没有用的.

but this is no use in this context.

如何获取/设置小部件信息?

How to get/set the widget information ?

推荐答案

使用 this._on()方法绑定处理程序.此方法由jQuery UI小部件工厂提供,并将确保在处理函数中,this始终引用小部件实例.

Use the this._on() method to bind the handler. This method is provided by the jQuery UI widget factory and will make sure that within the handler function, this always refers to the widget instance.

_create: function () {
    ...
    this._on(this.selectElement, {
        change: "_onChange" // Note: function name must be passed as a string!
    });
},
_onChange: function (event) {
    // 'this' is now the widget instance.
},

这篇关于在窗口小部件事件处理程序中时,如何访问窗口小部件选项中保存的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆