I can use this.config.<> to get any configurations in config.json from the Widget.js. But how can i access it from a usercreated.js?
Solved! Go to Solution.
Alex,
If the usercreated.js is called from the widgets Widget.js then all you need to do is pass a reference to the widget into the js file in the js files constructor or use a public var in your js file and set it to "this".
Alex,
If the usercreated.js is called from the widgets Widget.js then all you need to do is pass a reference to the widget into the js file in the js files constructor or use a public var in your js file and set it to "this".
Thanks again Robert. Worked.
the only thing is that if i have 100 parameters to pass, then I need to pass all of them as parameters in either the constructor or methods.
Alex,
NO absolutely not. Just pass the widget object (i.e. yourJS.parentWidget = this inside your Widget.js) and then you can use parentWidget.config.xyz in your js file.
ok, i think i was confused.
currently I can make it work like below. can you please share your codes so i can access all parameters in the config.json within User.js?
in config.json
"xyz": "USA",
"abc": "Canada"
...
in Widget.js
constructor: function (options) {
......
this.UserJS = UserJS.getInstance(options.config.xyz);
},
in User.js
clazz.getInstance = function (xyz) {
if (instance === null) {
instance = new clazz();
}
instance.xyz = xyz;
return instance;
};
so within User.js, console.log(this.xyz) will return "USA"
Alex,
In Widget.js you would create a new instance of your User.js i.e
var user = new User();
user.parentWidget = this;
and in the User.js you would have a public var like:
return declare([_WidgetBase, Evented], {
parentWidget: null;
The you use this.parentWidget.config.xyz as this.parentWidget a reference to the Widget.js.