【问题标题】:How get extjs-6 sotre's data in mvvm architecture?如何在 mvvm 架构中获取 extjs-6 sotre 的数据?
【发布时间】:2015-08-01 11:33:57
【问题描述】:

我正在使用MVVM architecture 开发一个Extjs 6 应用程序。我在MyApp/model 文件夹中有一个模型如下:

Ext.define('MyApp.model.User', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name',  type: 'string'},
        {name: 'age',   type: 'int'}
    ]
});

我在MyApp/store文件夹中的存储如下:

Ext.define('MyApp.store.User', {
    extend: 'Ext.data.Store',
    model: 'MyApp.model.User',
    data : [
     {firstName: 'Seth',    age: 34},
     {firstName: 'Scott', age: 72},
     {firstName: 'Gary', age: 19},
     {firstName: 'Capybara', age: 208}
    ]
});

Application.js/MyApp文件夹中添加store如下:

stores: [
    'User'
]

现在我在我的应用程序中存储如下:

app = MyApp.getApplication();
users = app.getStore('User');

如何获取商店数据users.getData()?当我使用users.getData() 时,它返回[undefined x 4]问题出在哪里是否正常工作

【问题讨论】:

  • 问题不正确。 MVVM - 模型视图 ViewModel。您没有 ViewModel。您应该在 ViewModel 中定义一个商店,并且可以通过 .getViewModel().get().getData() 获取数据。如果您只想遍历所有记录,您可以使用存储的“每个”方法而不是获取数据。无论如何,您的问题与 MVVM 无关。

标签: extjs mvvm extjs-mvc extjs6 extjs6-classic


【解决方案1】:

您使用正确。您必须使用users.getData().items 如下:

app = MyApp.getApplication(); users = app.getStore('User'); users.getData().items;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 2022-12-03
    • 2016-07-18
    • 2020-04-25
    • 2021-08-19
    相关资源
    最近更新 更多