Search code examples
dojojsonstore

Does a foreach loop work directly with a JSonStore data object store?


I create a JSonStore with a JSON formatted array of objects. I have verified it is properly formatted.

I then try to use a dojo forEach loop on it but the JSonStore doesn't seem to have any data in it. I can specify the target in my web page URL and it shows the right data. But using console.log(myJsonStore) shows an object but I don't see the data in Firebug. I also don't see any GET for the service providing the data. It's like specifying the target path in a URL in the browser fires the GET but not when I try to trigger it in the postCreate where my foreach is located.


Solution

  • The answer from Ricardo, i believe is a little incorrect, seeing as the JsonRest.query function returns a dojo.Deferred.

    You have a REST call being made asynchroniously through store read api - and once it returns values, it will promise to run whats set as the callback.

    Try this for your loop iterator instead

    storeObj.query( {} ).then(function ( results ) {
      dojo.forEach( results, function( obj ) {
        console.log( obj );
      });
    }