我需要关于xtemplate和带有代理的store的帮助。无论我尝试什么,我都陷入了这个问题。xtemplate只显示来自一个没有使用代理的store的数据。
有效的store:
Ext.create('Ext.data.Store', {
storeId : 'viewStore',
model : 'dataview_model',
data : [
{statistic: '213213', description: 'Hallo'},
{statistic: '534345', description: 'Alloh'},
]
});
使用Xtemplate和数据配置进行开发
xtype: 'component',
cls: 'kpi-tiles',
id: 'statisticsBoxes',
height: 100,
tpl: [
'<div class="kpi-meta">',
'<tpl for=".">',
'<span>',
'<div class="statsDiv">{statistic}</div> {description}',
'</span>',
'</tpl>',
'</div>'
],
data: [{
description: Ext.getStore('statisticsStore').getAt(0).data.statistic,
statistic: Ext.getStore('viewStore').getAt(0).data.statistic
},{
description: Ext.getStore('viewStore').getAt(1).data.description,
statistic: Ext.getStore('viewStore').getAt(1).data.statistic
}],
但是当我更改模板的数据以便从统计数据存储中加载数据时,控制台会出现以下错误: Uncaught TypeError: Cannot read property 'getAt' of undefined。
数据配置:
data: [{
description: 'the description',
statistic: Ext.getStore('statisticsStore').getAt(0).data.statistic
}],
统计存储:
Ext.define('ExecDashboard.store.Statistics', {
extend: 'Ext.data.Store',
alias: 'store.statistics',
storeId: 'statisticsStore',
model: 'ExecDashboard.model.Statistics',
proxy: {
type: 'ajax',
url: '/statistics',
reader: 'json'
}
});
生成以下JSON:
[{"statistic":"1"}, {"statistic":"2"}]
store已在viewModel中加载:
stores: {
Statistics: {
type: 'statistics',
autoLoad: true
}
}
我认为问题在于那个时候商店没有被加载。但是我不知道如何解决这个问题。我知道当商店被加载时,'Ext.getStore('statisticsStore').getAt(0).data.statistic' 在 console.log 中可以正常工作。
Ext.view.View
组件。 - Evan Trimboli