【问题标题】:ExtJS: get store attribute from parentExtJS:从父级获取存储属性
【发布时间】:2014-07-21 13:16:01
【问题描述】:

我有一个这样的组件

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

应使用此类的每个新实例创建商店,然后应该可以从数据视图项访问它。 这是 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() 函数,所以数据视图项似乎没有 up() 方法。 我的问题是:如何访问 store 实例?

感谢您的回复

【问题讨论】:

    标签: javascript extjs model-view-controller extjs4


    【解决方案1】:

    ([EDIT]:更改代码以将store定义为对象属性)

    你试过了吗?

    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/

    【讨论】:

    • -1,这不是一个好的做法,它不会做你认为它会做的事情。假设定义没有被包裹在一个闭包中或者任何它最终会设置window.store = foo;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 2017-04-13
    • 2017-02-13
    相关资源
    最近更新 更多