EXTJS7 构造函数constructor中的config

小编:管理员 462阅读 2022.09.07

extjs组件的构造函数可以获得两个config变量

constructor: function (config) {
    this.config
    this.callParent([config]);
},
复制
  • 传入参数config:实例化组件时传入的配置参数
  • 成员变量this.config: 组件类定义中的配置值 例如:
Ext.define('mybasecomp',{
  config: {myBaseProp: 'defaultBasePropValue'},
  constructor: function(config){
    config; // 值为 {myProp: 'propValue'}
    this.config; // 值为 {myProp: 'defaultPropValue', myBaseProp: 'basePropValue', __proto__: {myBaseProp: 'defaultBasePropValue'}}
	...
  }
});
Ext.define('mycomp',{
  extend: 'mybasecomp',
  myBaseProp: 'basePropValue'
  config: {myProp: 'defaultPropValue'},
  constructor: function(config){
    config; // 值为 {myProp: 'propValue'}
    this.config; // 值为 {myProp: 'defaultPropValue', myBaseProp: 'basePropValue', __proto__: {myBaseProp: 'defaultBasePropValue'}}
	...
  }
});
Ext.create('mycomp',{
  myProp: 'propValue'
});
复制
关联标签: