【问题标题】:How to get store value from Sencha extjs如何从 Sencha extjs 获取存储价值
【发布时间】:2017-02-13 08:18:13
【问题描述】:

我想从存储中检索所有数据,以便在 sencha extjs6 中进行一些验证。我有一个模型、一个商店和一个 json 文件。但我不知道如何从 json 中获取 store 值。例如,将 store 中的值存储到变量或数组中以供我进一步验证。请帮助我,因为我是 sencha extjs 的新手。 这是我的代码:

型号

Ext.define('MyApp.model.MobilePrefix', {

extend: 'Ext.data.Model',

config: {

    fields: [
        {name: 'id', type: 'int'},
        {name: 'prefix', type: 'string'},
        {name: 'length', type: 'int'}
    ]   
}
});

商店

Ext.define('MyApp.store.MobilePrefix', {

extend: 'Ext.data.Store',

requires: [
    'MyApp.model.MobilePrefix'
],

config: {
    model: 'MyApp.model.MobilePrefix',

    proxy: {
        type: 'ajax',
         url: 'resources/data/MobilePrefix.json',


        reader: {
            type: 'json',
            rootProperty: 'MobilePrefix'
        }
    },

    autoLoad: true
}

});

Json MobilePrefix.json

{
"MobilePrefix": [
    {"id": 1, "prefix":"012", "length":6 },
    {"id": 2, "prefix":"015", "length":6 },
    {"id": 3, "prefix":"097", "length":7 }
   ]
}

提前致谢。

【问题讨论】:

  • 必须添加验证的地方,使用 Ext.getStore('MobilePrefix').data 获取数据,然后添加验证代码。
  • 感谢您的反馈。我会试试的。

标签: json extjs store extjs6-modern


【解决方案1】:

在您的 Store 文件中使用监听器。

Ext.define('MyApp.store.MobilePrefix', {
extend: 'Ext.data.Store',
requires: ['MyApp.model.MobilePrefix'],
autoLoad: true,
config: {
    model: 'MyApp.model.MobilePrefix',
    proxy: {
        type: 'ajax',
        url: 'resources/data/MobilePrefix.json',


        reader: {
            type: 'json',
            rootProperty: 'MobilePrefix'
        }
    },
    listeners: {
        load: function(store) {
            console.log(store.data);
        }

    }
}
});

【讨论】:

    猜你喜欢
    • 2021-04-19
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-13
    • 2013-04-14
    • 1970-01-01
    • 2011-05-02
    相关资源
    最近更新 更多