I know this is stupid but I cannot figure out how to get my js to pull some of my config.json into it.
Does it have to be a function?
After viewing sample code, I see that it can be done with a function.
LocalLayer widget:
this.config.layers.layer.forEach(function (layer) {
Is there any documentation/ videos/ examples on how this can be done.
I am looking for a way to amend the config json and have the script reflect that.
Such as
js
var Exp = "fromjson";
json
"fromjson": "crime = 'Larceny/Theft' ",
Thanks!
Solved! Go to Solution.
I was having that same problem for a while. I think what I did to fix it was assign a variable in the js to the config value and then used the variable in the js code.
for example:
json
"crimes": "Month='January'"
widget
var crimeDate = this.config.crimes;
Then use crimeDate in the js code where you had "this.config.crimes" before.
-Stan
Rickey,
In a widget.js there is access to the widgets config.json by using the this.config object so if you have a object called crimes in your config.json then you can access this in the widget.js by using this.config.crimes.
Robert,
Thank you! I have tried that. I just keep getting an error of crimes not defined (assuming crimes is in my config.json).
Rickey,
Can You show me how you have "crimes" written in your json file?
Robert,
json
"crimes": "Month='January'"
widget
this.config.crimes
Rickey,
Is crimes a child of some other object? Can you share your whole json?
Robert,
Here is my json
I am assuming that if i wanted to do the layer in my json my code would be this.config.layers.layer
{ "crimes": "Month='January'", "layers": { "layer": [ { "type": "Feature", "url": "http://gis.ashland.or.us/arcgis/rest/services/sandbox/crimeloc/MapServer/2", "name": "crimeloc_filter", "opacity": 0.59, "visible": true, "showLabels": true, "popup": { "title": "Crime", "fieldInfos": [ { "fieldName": "crime", "label": "crime", "visible": true }, { "fieldName": "date", "label": "date", "visible": true }, { "fieldName": "time", "label": "time", "visible": true }, { "fieldName": "Address", "label": "Address", "visible": true }, { "fieldName": "Description", "label": "Description", "visible": true }, { "fieldName": "IncidntNum", "label": "IncidntNum", "visible": true }, { "fieldName": "Descript", "label": "Descript", "visible": true }, { "fieldName": "DayOfWeek", "label": "DayOfWeek", "visible": true }, { "fieldName": "Date_1", "label": "Date_1", "visible": true }, { "fieldName": "Time_1", "label": "Time_1", "visible": true }, { "fieldName": "PdDistrict", "label": "PdDistrict", "visible": true }, { "fieldName": "Resolution", "label": "Resolution", "visible": true }, { "fieldName": "Location", "label": "Location", "visible": true }, { "fieldName": "Month", "label": "Month", "visible": true } ], "showAttachments": true, "tr": null }, "autorefresh": 0, "mode": "ondemand" } ] } }
I was having that same problem for a while. I think what I did to fix it was assign a variable in the js to the config value and then used the variable in the js code.
for example:
json
"crimes": "Month='January'"
widget
var crimeDate = this.config.crimes;
Then use crimeDate in the js code where you had "this.config.crimes" before.
-Stan
Stan,
I tired that, my error is:
Rickey,
I don't see anything wrong in your json so the next question is where in your widget.js are you trying to access the this.config.crimes object (hopefully after postCreate method)?