在ExtJS 4中调用生命周期模板方法
在下面的示例代码中,我创建了一个自定义组件,它使用一些生命周期回调方法,如onRender在ExtJS 4中调用生命周期模板方法,extjs,extjs4,Extjs,Extjs4,在下面的示例代码中,我创建了一个自定义组件,它使用一些生命周期回调方法,如onRender Ext.onReady (function() { Ext.define("Person", { extend: "Ext.Component", constructor: function (config) { this.initConfig(config), this.callParent(); console.log("inside
Ext.onReady (function() {
Ext.define("Person", {
extend: "Ext.Component",
constructor: function (config) {
this.initConfig(config),
this.callParent();
console.log("inside constructor");
return this
},
onRender: function() {
this.callParent(arguments);
console.log("inside onRender");
},
});
Ext.create('Person', {
width:200,
height:300,
html: "hello world",
renderTo: Ext.getBody()
});
}))
输出:“内部构造函数”
看起来没有调用onRender的生命周期方法。此外,“hello world”也不会被渲染
我做错了什么?我不知道确切的答案是什么。。但是我试着回答,如果我错了,请纠正我 据我所知,
callparent()
用于调用其父函数中的函数,该函数可能需要传递参数,在本例中,构造函数需要传递数组
Ext.onReady (function() {
Ext.define("Person", {
extend: "Ext.Component",
constructor: function (config) {
//this.initConfig(config),
this.callParent([config]);
console.log("inside constructor");
//return this
},
onRender: function() {
this.callParent(arguments);
console.log("inside onRender");
},
});
Ext.create('Person', {
width:200,
height:300,
html: "hello world",
renderTo: Ext.getBody()
});
});
this.callParent([config])代码>表示使用参数config或此作用域调用父级。。
因此,Ext.component
中的onRender
函数会被您的onRender
覆盖。…没错。忘记在callParent调用中传递参数。传入配置的数组也可以工作。