Pergunta

Morning,

I have created a store in my controller like this:

    var storeCompanies = new Ext.data.JsonStore({
      proxy: new Ext.data.HttpProxy({
          type: 'GET',
        url: url+'dashboard?Uid='+uid+'&Ude='+ude,
        reader: {
            type: 'json',
            root: 'root',
            totalProperty: 'total'
        },
        headers: {
           'Accept' : 'application/json;application/x-www-form-urlencoded',
           'Content-Type' : 'application/x-www-form-urlencoded',
        },

      }),
      root: 'd',
      type: 'localstorage',
      autoLoad : true,
      id: 'company_Id',
      scope : this,
      fields: ['Name']
    });
console.log(storeCompanies);

The console log shows that the store is being created and populated properly. I need to retrieve all the values for a dropdown.
I tried this but it returned undefined. All other info I have found seems to instruct on how to find just one value. What's the easiest and most effecient way to retrieve all the data?

Foi útil?

Solução

storeCompanies.on('load', function() {
    console.log(storeCompanies.data); //<--- data is a Ext.util.MixedCollection
});

Outras dicas

If you need to retrieve all the values in the JSonStore you could use each(). Here's an example: http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.JsonStore-method-each

Thanks to @Vlad for his input. Here is what I settled on:

storeCompanies.on('load', function() {
    numcomps = storeCompanies.data.items.length; //get number of elements in store
    for(var ic = 0;ic<numcomps;ic++){
        console.log(storeCompanies.data.items[ic].raw);
    }
});
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top