我有这样的组件
Ext.define('Fleximanager.view.pages.home', {
extend: 'Fleximanager.view.main.FlexiTab',
store: Ext.create('Fleximanager.store.hometables'), // this is the store for each instance
items: [{
xtype: 'dateselector'
},{
xtype: 'dataview',
flex: 5,
store: this.up('flexitab').store, //this store should be the same as above
itemTpl: new Ext.XTemplate(
//the xtemplate here
)
}]
});
应该使用此类的每个新实例创建存储,然后可以从dataview项访问它。 这是FlexiTab的定义:
Ext.define('Fleximanager.view.main.FlexiTab', {
extend: 'Ext.panel.Panel',
xtype: 'flexitab',
requires: [
'Fleximanager.view.tools.DateSelector'
],
closable: true,
layout: {
type: 'vbox',
align: 'stretch'
},
initComponent: function(){
this.reload();
this.renderTo = Ext.getBody();
this.callParent();
},
reload: function(extraParams){
params = {
hostname: sessionStorage.hostname,
auth: sessionStorage.authSessionId,
corp: sessionStorage.activeCorp
};
if(typeof extraParams !== "undefined"){
for (var key in extraParams){
params[key] = extraParams[key];
}
}
this.store.load({
params: params,
callback: function(records, operation, success) {
console.log('successfully loaded store: ', records);
}
});
}
});
但是我总是得到一个错误:Uncaught TypeError: undefined is not a function
引用up()函数,所以看起来dataview项没有up()方法。
我的问题是:如何访问商店实例?
感谢您的回复
答案 0 :(得分:0)
([ EDIT ]:更改了代码以将商店定义为对象属性)
你试过这个吗?
Ext.define('Fleximanager.view.pages.home', {
extend: 'Fleximanager.view.main.FlexiTab',
initComponent: function(){
this.store = Ext.create('Fleximanager.store.hometables');
this.items = [{
xtype: 'dateselector'
},{
xtype: 'dataview',
flex: 5,
store: this.store, //this store should be the same as above
itemTpl: new Ext.XTemplate(
//the xtemplate here
)
}];
Ext.Panel.prototype.initComponent.apply(this, arguments);
}
});
您可以在此处查看示例:http://jsfiddle.net/6ubSL/