如何从sencha中的jsonstore检索所有数据

时间:2013-08-08 09:57:50

标签: extjs jsonstore

上午,

我在我的控制器中创建了一个商店,如下所示:

    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);

控制台日志显示正在创建并正确填充存储。我需要检索下拉列表的所有值 我试过this,但它返回undefined。 我发现的所有其他信息似乎都指示如何找到一个值。 检索所有数据的最简单,最有效的方法是什么?

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

如果需要检索JSonStore中的所有值,可以使用each()。这是一个例子:http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.JsonStore-method-each

答案 2 :(得分:0)

感谢@Vlad的投入。以下是我的决定:

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);
    }
});