admin管理员组文章数量:1390965
I am programming a new jquery-ui widget from scratch. I found the official 'how widget factory works' document. (/)
The widget itself works fine.
Now I want to store some values internally - is there a preferred way to do this?
All properties that are declared in options are public I think.
Thanks for your help!
I am programming a new jquery-ui widget from scratch. I found the official 'how widget factory works' document. (http://jqueryui./demos/widget/)
The widget itself works fine.
Now I want to store some values internally - is there a preferred way to do this?
All properties that are declared in options are public I think.
Thanks for your help!
Share Improve this question edited Jul 31, 2013 at 20:34 mu is too short 435k71 gold badges859 silver badges818 bronze badges asked Jan 4, 2012 at 17:38 Stefan Krüger s-lightStefan Krüger s-light 1,02411 silver badges28 bronze badges1 Answer
Reset to default 8Just use plain old properties on this
. For example, a basic widget will look something like this:
$.widget('some_name', {
options: { /* ... */ },
_create: function() {
// ...
this.internal_value = 11;
// ...
},
frobnicate_by: function(this_much) {
this.internal_value += this_much;
}
// ...
});
And you can set up your internal values as properties of this
as desired. For example, the above sets this.internal_value
to an initial value of 11 and $(s).some_name('frobnicate_by', 23)
would change the internal_value
.
You can see an example of an internal property in the example widget you linked to by looking for this.changer
.
The options
are used for things that can be configured when someone creates an instance of your widget. Internal settings don't need any special handling, they're just plain old object properties; one of the nice things about the widget factory is that it makes it easy to do normal OO things in your widgets.
本文标签: javascriptHow to store a internal property in jqueryui widgetStack Overflow
版权声明:本文标题:javascript - How to store a internal property in jquery-ui widget? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744636969a2616880.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论