gpt4 book ai didi

javascript - ExtJS:从父级获取商店属性

转载 作者:行者123 更新时间:2023-11-28 08:12:49 26 4
gpt4 key购买 nike

我有一个这样的组件

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
)
}]
});

应该使用此类的每个新实例创建存储,然后应该可以从数据 View 项访问它。这是 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() 方法。我的问题是:如何访问商店实例?

感谢您的回复

最佳答案

([编辑]:更改了代码以将存储定义为对象属性)

你试过这个吗?

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/

关于javascript - ExtJS:从父级获取商店属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23977285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com