解析jsonstore内容

Parsing jsonstore content

本文关键字:内容 jsonstore 解析      更新时间:2023-09-26

jsonstore加载的数据如下:

"[{"Year":"2014","Total":"5.6","Rank":"6","Share":"6"},
{"Year":"2013","Total":"5.6","Rank":"6","Share":"6"},
{"Year":"2014","Total":"5.6","Rank":"6","Share":"6"},
{"Year":"2013","Total":"5.6","Rank":"6","Share":"6"}]"

我们需要迭代响应:

FeesByProduct_store = new Ext.data.JsonStore({
        root: 'list',
        url: '...............', 
      fields: FeeByProduct,
        listeners: {load: function(store) {
            //create a json object from the response string
            var res = Ext.encode(Ext.pluck(store.data.items, 'data'));
            // if we have a valid json object, then process it
            if(res !== null &&  typeof (res) !==  'undefined'){
                // loop through the data
                Ext.each(res, function(obj){
                    //add the records to the array
                    if (obj != null) {
                    ...
                    }   
                });
             }
        }
    }
    }); 

但是,在迭代时- 'obj'包含响应的整个值,而不是一次包含每一行。
这里做错了什么?

如果您已经成功加载了存储,那么原始json就不再有趣了。存储中有很多方法可以用来检查或操作存储记录。

您的加载侦听器可以像这样:

load:function() {
    this.each(function(record) {
        // do something with record here, for example
        console.log(record.getData();
    }
}

查看store文档,找到可以用来实现所需功能的其他方法。