if (typeof response == "object") {
store = new dojo.data.ItemFileReadStore({
data : response
});
console.warn("Loaded to Store");
var itemArray = new Array();
var completed = function(items) {
for(var i = 0; i < items.length; i++) {
console.log(store.getValue(items[i],"itemlabel"));
itemArray.push(store.getValue(items[i]));
}
};
var error = function() {
console.log("Error in fetching data from Store");
};
store.fetch({onComplete: completed, onError: error});
console.warn("Item count"+ itemArray.length);
So my Item Count gives Always 0 but
console.log(store.getValue(items[i],"itemlabel"));
In the callback method the above get print the value.
So if i want to populate my itemArray what can i do?
You’re printing
itemArray.lengthbefore the array gets populated with any data in thecompletedfunction, becausecompletedwill be called asynchronously.If you want to print the actual length of
itemArray, you should do it after the for-loop incompleted.