【发布时间】:2015-11-13 08:58:49
【问题描述】:
我已经阅读了许多其他具有相同问题的帖子,但似乎没有一个能给我解决问题所需的答案。
我已将我的数据存储区定义如下:
Ext.define('TestApp.store.tbData', {
extend: 'Ext.data.Store',
alias: 'store.tbData',
storeId: 'tbData',
fields: [
'name', 'number', 'key', 'priority'
],
data: {
items: [
{name: 'a', number: 'b', key: 'c', priority: 'd'}
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
那我也有我的主要观点:
Ext.define('TestApp.Templates.tbTemplate', {
extend: 'Ext.window.Window',
alias: 'tbTemplate',
itemId: 'tbWindow',
viewModel: {
type: 'test'
},
requires: [
'TestApp.Controllers.tbController',
'TestApp.store.tbData',
'TestApp.Controllers.dateTimeController'
],
controller: 'tbTemplate',
autoShow: true,
height: 600,
width: 600,
constrainHeader: true,
title: 'tb',
items: [
{
xtype: 'gridpanel',
store: {
type: 'tbData'
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'number',
text: 'Number'
},
{
xtype: 'gridcolumn',
dataIndex: 'key',
text: 'Key'
},
{
xtype: 'gridcolumn',
dataIndex: 'priority',
text: 'Priority'
}
]
}
]
});
其中有一个控制器:
Ext.define('TestApp.Controllers.tbController', {
extend: 'Ext.app.ViewController',
singleton: true,
alias: 'controller.tbTemplate',
config:{stores: ['tbData'],},
requires: [
'TestApp.store.tbData'
],
windowOpened: function () {
console.log(Ext.getStore('tbData'));
}
});
在控制器中,当我调用 windowOpened 函数时,我试图获取数据存储区,因此最终我可以动态地向其中添加更多数据行。我可以显示我放在行中的测试数据,但我似乎无法按照我尝试的方式连接到数据存储。任何关于为什么它返回未定义以及如何解决它的帮助将不胜感激。
我已尝试使用将其添加到我的 Application.js 文件夹中
stores: ['TestApp.store.tbData']
也没有运气。
谢谢。
【问题讨论】:
-
你试过这个吗:
Ext.getStore('TestApp.store.tbData')? -
我已经尝试了很多变体并且都返回未定义,所以我知道它只是在连接而不是返回一个值,因为它正在寻找它看起来的位置
-
您在 Application.js 中尝试过
stores: ['tbData']吗? -
另一个建议是删除(或评论)
viewModel配置和网格中的store: 'tbData', -
我现在得到一个错误'Uncaught TypeErrorL Cannot read property 'isBufferedStore' of undefined...我注释掉了 viewmodel 并将网格存储更改为你所说的。
标签: extjs undefined datastore extjs6