简体   繁体   中英

Extjs 3.4 custom JSONReader

I haven't had a question from quite a while, but I finally ended up hitting a wall here. Anyways, to make this easy. I am trying to create a JSON store in extjs 3.4 (work related, and no I am not updating). Well, I created the queries as usual with the proper response and fill it up. My problem is that I have 1 extra property on the JSON that I want to be able to pull and use on the app. Sample of my JSON from the response object in chrome:

myInventory: [{Priority:1, PMNumber:444, Description:fix-a-tape, Assets:3, Storage_Count:0,…},…]
percent: 97.040498442368
totalCount: "3"

Now, I know this is correctly formatted because the Grid I am using gets populated, but I can't get the percent property. So my question is, how do you pull an extra parameter on the datastore building block of code when you have one extra parameter that is not usual on EXTjs, in my case the percent? I tried doing a metachange on the JSONReader, but all I get is percent:"percent" on the properties as I inspect the datastore after it's creation.

Ext.data.JsonReader has a property jsonData which is exactly what you need. A quick example:

Ext.onReady(function() {
    var store = new Ext.data.JsonStore({
        url: 'data/test.json',
        root: 'dataRoot',
        fields: ['fieldA', 'fieldB'],
        idProperty: 'id',
        storeId: 'myStore'
    });

    store.on('load', function(store) {
        console.log(store.reader.jsonData.someOtherProperty);
    });

    store.load(); 

});

and the data/test.json looks like this:

{
    dataRoot: [{
        id: 0,
        fieldA: 'a',
        fieldB: 'b' 
    }],
    someOtherProperty: 'abc'
}

There could also be an alternative approach that you manually (not via store.load()) perform Ext.Ajax request, use the properties you need and then manually call Ext.data.JsonStore.loadData() using the data you got from Ajax request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM