How to retrieve JSON Data Array from ExtJS Store

后端 未结 15 2044
忘掉有多难
忘掉有多难 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:20

    I run into my share of trouble trying to access data from store without binding it to a component, and most of it was because store was loaded trough ajax, so it took to use the load event in order to read the data. This worked:

    store.load();
    store.on('load', function(store, records) {
        for (var i = 0; i < records.length; i++) {
        console.log(records[i].get('name'));
        };
    });
    
    0 讨论(0)
  • 2020-12-04 17:21
    proxy: {
            type: 'ajax',
            actionMethods: {
                read: 'POST',
                update: 'POST'
            },
            api: {
                read: '/bcm/rest/gcl/fetch',
                update: '/bcm/rest/gcl/save'
            },
            paramsAsJson: true,
            reader: {
                rootProperty: 'data',
                type: 'json'
            },
            writer: {
                allowSingle: false,
                writeAllFields: true,
                type: 'json'
            }
        }
    

    Use allowSingle it will convert into array

    0 讨论(0)
  • 2020-12-04 17:23

    Try this:

    myStore.each( function (model) {
        console.log( model.get('name') ); 
    }); 
    
    0 讨论(0)
  • 2020-12-04 17:26

    You don't need to make any loops and collect/reprocess data. The json object you need is here:

    var jsonData = store.proxy.reader.jsonData;
    
    0 讨论(0)
  • 2020-12-04 17:29

    Store.getRange() seems to be exactly what you are searching for. It will return you Ext.data.Record[] - array of records. If no arguments is passed, all the records are returned.

    0 讨论(0)
  • 2020-12-04 17:30

    I always use store.proxy.reader.jsonData or store.proxy.reader.rawData

    For example - this return the items nested into a root node called 'data':

    var some_store = Ext.data.StoreManager.lookup('some_store_id');
    Ext.each(some_store.proxy.reader.rawData.data, function(obj, i){
       console.info(obj);
    });
    

    This only works immediately after a store read-operation (while not been manipulated yet).

    0 讨论(0)
提交回复
热议问题