【问题标题】:How can I load some data into Ext.data.Store如何将一些数据加载到 Ext.data.Store
【发布时间】:2012-11-09 08:56:17
【问题描述】:

这是我的代码

        var store = {
            roles_store: new Ext.data.Store({
                        autoLoad: false,
                        proxy: new Ext.data.HttpProxy({
                                                        url: 'a/b/c',
                                                      }),
                        remoteSort: true, 
                        baseParams: {

                                    },
                        reader: new Ext.data.JsonReader({
                                                totalProperty: 'total',
                                                root: 'root',
                                                fields:['roles']                
                                                        }),

            })
        };

这是我的 json

{"total":3,"root":[{"roles":"A"},{"roles":"B"},{"roles":"C"}]}

如果我想将数据添加到 Ext.data.Store。我能怎么做?

(PS:对不起,我的英文不好。而我的extjs是:http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.Store-method-添加排序)

【问题讨论】:

    标签: extjs


    【解决方案1】:

    这应该可行:

    Ext.define('roles', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'roles', type: 'string'}
        ]
    });
    
    var myStore = Ext.create('Ext.data.Store', {
        model: 'roles',
        proxy: {
            type: 'ajax',
            url : 'path/to/data/test.json',
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'total'
            }
        },
        autoLoad: true
    });
    

    在此处查看示例:http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store

    对于 v3.4:

    var store = new Ext.data.JsonStore({
    
        autoDestroy: true,
        url: 'path/to/data/test.json',
        storeId: 'myStore',
        autoLoad: true,
        idProperty: 'roles',
        root: 'root',
        fields: ['roles'] 
    });
    

    你需要使用jsonstore: http://docs.sencha.com/ext-js/3-4/#!/api/Ext.data.JsonStore

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 2012-06-02
    • 1970-01-01
    • 2013-02-22
    • 1970-01-01
    相关资源
    最近更新 更多