Extjs从新窗口引用父窗口

Extjs refer to parent window from new window

本文关键字:窗口 引用 新窗口 Extjs      更新时间:2023-09-26

使用Extjs 5.0.1我有一个带有按钮的Ext.toolbar.Toolbar。当我点击按钮时,会打开一个新窗口,里面有一个表单。在表单内,我需要参考工具栏,但使用form.up('toolbar')不工作,它返回undefined。这似乎是因为新窗口没有与工具栏绑定。我不想使用getCmp,因为我没有使用id属性。

你知道吗?

您可以使用Ext.ComponentQuery.query来查找工具栏

使用xtype toolbar,它将返回一个对象数组。

 Ext.ComponentQuery.query('toolbar')[0];

如果你有多个工具栏,你可以给工具栏配置一个唯一的itemId,如itemId:'buttonToolbar'

 Ext.ComponentQuery.query('#buttonToolbar')[0];

同样,你给配置工具栏一个唯一的名字,如name:'buttonToolbar'

Ext.ComponentQuery.query('toolbar[name=buttonToolbar]')[0];
onBtnABCClick:function(btn) {
    Ext.create('MyApp.view.NewWindow',{
        myParentToolbar: btn.up('toolbar') // <- here you give your new window a config item
    });
}

onWindowAfterRender:function(component) {
    // here you can access the new config item:
    component.config.myParentToolbar.down('button[itemId=ABC]').setDisabled(true);
    // in ExtJS 4, it was "component.myParentToolbar", in ST2 "component.config.myParentToolbar".
    // Unsure about ExtJS 5, please test both possibilities.
}