How to retrieve JSON Data Array from ExtJS Store

后端 未结 15 2043
忘掉有多难
忘掉有多难 2020-12-04 17:04

Is there a method allowing me to return my stored data in an ExtJS Grid Panel exactly the way I loaded it using:

var data = [\"value1\", \"value2\"]
Store.lo         


        
相关标签:
15条回答
  • 2020-12-04 17:09

    A simple way to do this is

    var jsonArray = store.data.items
    

    So if your JSON store is

    [{"text": "ABC"}, {"text": "DEF"},{"text": "GHI"},{"text": "JKL"}]
    

    Then you can retreive "DEF" as

    jsonArray[1].data.text
    

    In the following code, I noticed that it converts each and every character into an array item.

    var jsonData = Ext.encode(Ext.pluck(store.data.items, 'data'));
    
    0 讨论(0)
  • 2020-12-04 17:12

    A one-line approach:

    var jsonData = Ext.encode(Ext.pluck(store.data.items, 'data'));

    Not very pretty, but quite short.

    0 讨论(0)
  • 2020-12-04 17:12
     function getJsonOfStore(store){
            var datar = new Array();
            var jsonDataEncode = "";
            var records = store.getRange();
            for (var i = 0; i < records.length; i++) {
                datar.push(records[i].data);
            }
            jsonDataEncode = Ext.util.JSON.encode(datar);
    
            return jsonDataEncode;
        }
    
    0 讨论(0)
  • 2020-12-04 17:15

    A better (IMO) one-line approach, works on ExtJS 4, not sure about 3:

    store.proxy.reader.jsonData
    
    0 讨论(0)
  • 2020-12-04 17:16

    In my case I wanted a javascript jagged array e.g. [["row1Cell1", "row1cell2"],["row2Cell1", "row2cell2"]] based on the contents of the Ext grid store.

    The javascript as below will create such an array, dropping the id key in the object which I didn't need.

    var tableDataArray = [];
    Ext.ComponentQuery.query('[name="table1"]')[0].store.each(function(record){
        var thisRecordArray = [];
        for (var key in record.data) {
            if (key != 'id') {
                thisRecordArray.push(record.data[key]);
            }
        }
        tableDataArray.push(thisRecordArray);
    });
    
    0 讨论(0)
  • 2020-12-04 17:18

    As suggested above I tried below one with fail.

    store.proxy.reader.jsonData
    

    But below one worked for me

    store.proxy.reader.rawData
    
    0 讨论(0)
提交回复
热议问题