简体   繁体   English

Extjs 3.4自定义JSONReader

[英]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). 我正在尝试在extjs 3.4中创建一个JSON存储(与工作相关,不,我没有更新)。 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. 我的问题是,我希望能够在应用程序上提取和使用JSON上的1个额外属性。 Sample of my JSON from the response object in chrome: 来自chrome响应对象的JSON样本:

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. 现在,我知道这是正确的格式,因为我正在使用的Grid已填充,但是我无法获取percent属性。 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? 所以我的问题是,当您有一个在EXTjs上不常用的额外参数时,如何在代码的数据存储构建块上拉一个额外的参数,以我的情况来说是百分比? 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. 我尝试在JSONReader上进行元更改,但是在创建数据存储区时检查数据存储区时,我得到的只是属性的百分比:“ percent”。

Ext.data.JsonReader has a property jsonData which is exactly what you need. Ext.data.JsonReader具有属性jsonData ,正是您所需要的。 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: 和data / test.json看起来像这样:

{
    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. 还有一种替代方法,您可以手动(而不是通过store.load())执行Ext.Ajax请求,使用所需的属性,然后使用从Ajax获得的数据手动调用Ext.data.JsonStore.loadData()请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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