I have a situation that widget A needs to access the config file of widget B. Widget A already has its own config file. I need to compare a field between the two configs from widget A js file. Possible? Thanks.
Solved! Go to Solution.
You can get it from the appConfig like this (this is the best way if the widget has yet to be loaded):
this.appConfig.widgetOnScreen.widgets[8].config
Lefteris,
Inside a widget you can use this.appConfig to get the main config.json. Or you can use widgetmanager to getthe the other widget object and use the widget object like widgetB.config.
Thank you. I haven't used the widget manager for a while and forgot about it.
You can get it from the appConfig like this (this is the best way if the widget has yet to be loaded):
this.appConfig.widgetOnScreen.widgets[8].config
Similar to this question, to access, for an example, a function from another module, can I use this setup without using the widgetmanager? If I can, do I call the function correctly? Thanks.
Module A:
define(["dojo/_base/declare",
-------
--------
"./ModuleB",
--------
---------
],
function (declare,
------
------
ModuleB,
-------
-------
){
return declare([BaseWidget, _WidgetsInTemplateMixin], {
-------
-------
startup: function () {
-------
-------
ModuleB.loadSavedSessionsFromFile();
--------
--------
},
------
Lefteris,
What you have above is not using WidgetManager at all..? If you use widget manager then you can get a reference to the actual widget object and then call a function inside that widget. There are many threads on using WidgetManager to get a widget object back.
I need to revise my question. I am trying to reach a function that is in another js file (not part of a widget). I'd like to have an external js where a large number of functions will be hosted and any function can be easily called by the js of the widget.
As the script shows, one widget accessing a local js. Sorry, I was not clear.
define(["dojo/_base/declare",
-------
--------
"./localjs",
--------
---------
],
function (declare,
------
------
localjs,
-------
-------
){
return declare([BaseWidget, _WidgetsInTemplateMixin], {
-------
-------
startup: function () {
-------
-------
localjs.loadSavedSessionsFromFile();
--------
--------
},
------
Lefteris,
I don't see anything wrong with that pattern of coding if the local.js is coded as a module.
define(['dojo/_base/declare',
'dojo/Evented',
'dojo/on',
'dojo/_base/lang',
'dojo/_base/html',
'esri/request',
'esri/tasks/query',
'esri/tasks/QueryTask',
'esri/tasks/FeatureSet',
'dojo/keys',
'dojo/date/locale'
],
function (declare, Evented, on, lang, html, esriRequest, Query, QueryTask, FeatureSet, keys, locale) {
return declare([Evented], {
....
Somehow it does not work...It should be simple enough.
Widget A
define(['dojo/_base/declare', './test', 'jimu/BaseWidget'],
function(declare, test, BaseWidget) {
//To create a widget, you need to derive from BaseWidget.
return declare([BaseWidget], {
// DemoWidget code goes here
//please note that this property is be set by the framework when widget is loaded.
//templateString: template,
baseClass: 'jimu-widget-demo',
postCreate: function() {
this.inherited(arguments);
console.log('postCreate');
},
startup: function() {
this.inherited(arguments);
this.mapIdNode.innerHTML = 'map id:' + this.map.id;
test.myfunction();
//myfunction();
},
});
});
test.js
define(['dojo/_base/declare',
'dojo/Evented',
'dojo/on',
'dojo/_base/lang',
'dojo/_base/html',
'esri/request',
'esri/tasks/query',
'esri/tasks/QueryTask',
'esri/tasks/FeatureSet',
'dojo/keys',
'dojo/date/locale'
],
function (declare, Evented, on, lang, html, esriRequest, Query, QueryTask, FeatureSet, keys, locale) {
return declare([Evented], {
// DemoWidget code goes here
//please note that this property is be set by the framework when widget is loaded.
//templateString: template,
myfunction: function(){
alert("Can you see me now?")
}
});
});
Lefteris,
you need to us the new keyword:
var x = new test();
x.myfunction();