在 Ext.js 中,可以使用子组件的引用来调用子组件的方法。以下是示例代码:

Ext.define('MyApp.view.Parent', {
    extend: 'Ext.panel.Panel',
    xtype: 'parent',

    items: [{
        xtype: 'child',
        reference: 'myChild'
    }],

    onButtonClick: function() {
        var child = this.lookupReference('myChild'); // 获取子组件引用
        child.myMethod(); // 调用子组件的方法
    }
});

Ext.define('MyApp.view.Child', {
    extend: 'Ext.panel.Panel',
    xtype: 'child',

    myMethod: function() {
        console.log('子组件的方法被调用');
    }
});

在上面的示例中,父组件 Parent 中包含一个子组件 Child,并在子组件上设置了引用 myChild。在父组件的 onButtonClick 方法中,通过 lookupReference 方法获取子组件的引用,然后就可以调用子组件的方法 myMethod

需要注意的是,子组件必须是通过 reference 属性设置了引用才能被父组件获取到。如果没有设置引用,父组件就无法直接访问子组件的方法。

extjs 中父组件如何调用子组件的方法

原文地址: http://www.cveoy.top/t/topic/L1j 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录