I am facing an issue with populating a Combobox dynamically using a jsonRest from a cross-origin request.
While I have managed to do it statically (if that's the correct term), I am struggling to implement it for multiple cases. This is just a small part of a larger website with five Comboboxes.
Below is the code snippet:
require([
"dojo/_base/array",
"dojo/store/Memory",
"dojo/store/JsonRest",
"dijit/form/ComboBox",
"dojo/store/Cache",
"dojo/store/Observable",
"dijit/form/Textarea",
"dojo/domReady!"
],
function(array, Memory, JsonRest, ComboBox, Cache, Observable, Textarea){
var myArray = new Array;
var myStore = new Observable (new Cache (new JsonRest ({
target: “URL / target”,
idProperty: "WA",
headers: { "X-Requested-With": "" }
}), new Memory ()));
var myTextarea = new Textarea ({
name: "myarea",
style: "width:200px;"
}, "myarea");
myStore.query().then(function(response){
});
store = new Memory({data: myArray});
var comboBoxWA = new ComboBox({
id: "comboWA",
name: "WA",
value: "",
store: store,
searchAttr: "WA"
}, "comboWA");
myStore.query().then(function(response){
dojo.forEach( response, function( obj ) {
for (var p in obj) {
if(p=="WA"){
//I'm currently stuck at this point where I can't change the “WA” in myArray.push to a global Variable.
myArray.push({"WA" : obj[p]});
console.debug(myArray.toSource());
}}
});
});
});
The JSON response appears like this [Object { WA=‘'WA_30_14"}, Object { WA="WA_30_12"} , Object { WA="WA_30_10"}, Object { WA="WA_30_16"},…]
If anyone has any ideas or a simple example to share, it would be greatly appreciated. Thanks, Georg