Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs 4-如何在initComponent函数中升级到父组件_Extjs_Extjs4.1 - Fatal编程技术网

Extjs 4-如何在initComponent函数中升级到父组件

Extjs 4-如何在initComponent函数中升级到父组件,extjs,extjs4.1,Extjs,Extjs4.1,我定义了一个网格面板,如 Ext.define('Example', { extend: 'Ext.grid.Panel', alias: 'myGrid', store:Ext.create('Ext.data.Store', { fields: [ {name: 'name'} ] }), initComponent:

我定义了一个网格面板,如

    Ext.define('Example', {
        extend: 'Ext.grid.Panel',   
        alias: 'myGrid',
        store:Ext.create('Ext.data.Store', {
            fields: [
                {name: 'name'}
            ]
        }),
        initComponent: function() {
             alert(this.up('window').title); //but error like this.up(...) is undefined
             this.callParent(arguments);
        }
    ...
我创建了一个窗口,上面有一个项目

   items: {  
        xtype: 'myGrid'
    }

我想在父组件中得到一些东西。如何在initComponent函数中最多使用
父组件
。谢谢

你不能。在将组件添加到容器之前,必须首先实例化该组件。您可以重写
onAdded
模板方法,当组件添加到容器中时将调用该方法:

Ext.define('Foo',
    extend: 'Ext.Component',

    onAdded: function(ct) {
        this.callParent(arguments);
        console.log('Added to', ct);
    }
});

你不能。在将组件添加到容器之前,必须首先实例化该组件。您可以重写
onAdded
模板方法,当组件添加到容器中时将调用该方法:

Ext.define('Foo',
    extend: 'Ext.Component',

    onAdded: function(ct) {
        this.callParent(arguments);
        console.log('Added to', ct);
    }
});

这很好,但是如果我在
渲染函数
中初始化一个变量,并在外部警告它该变量不起作用,那么只能在
渲染函数
内部工作?@LookAtMeNow是的。“up()”将在向DOM添加组件后工作。这很好,但如果我在
渲染函数
内部初始化变量,并在外部警告该变量不工作,则只能在
渲染函数
内部工作?@LookAtMeNow Yes。将组件添加到DOM后,“up()”将正常工作。不确定这有多困难,但可以。不确定这有多困难,但可以。