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

标签 javascript extjs model-view-controller extjs4

我有一个这样的组件

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/

相关文章:

javascript递归函数返回初始值

javascript - 在具有另一个域的 iframe 上运行 javascript

javascript - 简单 JS slider 上的递归过多

javascript - Node.js 加密输入/输出类型

javascript - 按钮点击事件 Ext JS

asp.net-mvc-3 - IIS 7.5 和 MVC 3 使用 Windows 身份验证 - 为静态内容获取 401,但永远不会提示输入凭据

JavaFX - 主 Controller 调用子 Controller 的函数,导致空指针异常

extjs - ExtJS 编辑器网格/网格中的单选组

extjs - 如何交换 Extjs 面板内容?

c# - 从链接表中检索数据并将其显示在 View 中