extjs怎么做父子组件传参
可以通过以下步骤实现父子组件之间的参数传递:
- 在父组件中定义一个属性,存储子组件需要的参数:
Ext.define('MyApp.view.ParentComponent', {
extend: 'Ext.panel.Panel',
xtype: 'parentcomponent',
config: {
childParam: null // 存储子组件需要的参数
},
items: [{
xtype: 'childcomponent',
childParam: '{childParam}' // 将子组件的 childParam 属性与父组件的 childParam 属性绑定
}]
});
- 在子组件中定义一个属性,用于接收父组件传递的参数:
Ext.define('MyApp.view.ChildComponent', {
extend: 'Ext.panel.Panel',
xtype: 'childcomponent',
config: {
childParam: null // 接收父组件传递的参数
},
items: [{
xtype: 'textfield',
fieldLabel: 'Child Parameter',
bind: '{childParam}' // 将子组件的文本框与 childParam 属性绑定,显示父组件传递的参数
}]
});
- 在父组件中实例化并设置 childParam 属性:
Ext.create('MyApp.view.ParentComponent', {
childParam: 'Hello World',
renderTo: Ext.getBody()
});
这样,父组件就可以将参数传递给子组件,并在子组件中显示。
原文地址: https://www.cveoy.top/t/topic/bgLH 著作权归作者所有。请勿转载和采集!