extjs父组件给子组件传参
可以使用以下方法来实现父组件向子组件传参:
- 使用props
在父组件中,使用props来传递参数到子组件。在子组件中,使用this.props来访问这些参数。
父组件:
Ext.define('MyApp.view.Parent', {
extend: 'Ext.panel.Panel',
xtype: 'parent',
items: [{
xtype: 'child',
myParam: 'Hello World'
}]
});
子组件:
Ext.define('MyApp.view.Child', {
extend: 'Ext.panel.Panel',
xtype: 'child',
initComponent: function() {
this.callParent(arguments);
console.log(this.myParam); // Output: Hello World
}
});
- 使用listeners
在父组件中,使用listeners来监听子组件的事件。在子组件中,触发这些事件,并传递参数。
父组件:
Ext.define('MyApp.view.Parent', {
extend: 'Ext.panel.Panel',
xtype: 'parent',
items: [{
xtype: 'child'
}],
listeners: {
childEvent: function(param) {
console.log(param); // Output: Hello World
}
}
});
子组件:
Ext.define('MyApp.view.Child', {
extend: 'Ext.panel.Panel',
xtype: 'child',
myMethod: function() {
this.fireEvent('childEvent', 'Hello World');
}
});
原文地址: https://www.cveoy.top/t/topic/bRWr 著作权归作者所有。请勿转载和采集!