【发布时间】: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