如何解决在ExtJS 4中调用生命周期模板方法
| 在下面的示例代码中,我创建了一个自定义组件,该组件使用了一些生命周期回调方法,例如onRenderExt.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”。
我究竟做错了什么?
解决方法
我不知道确切的答案..但是我尝试回答,如果我错了,请更正我。
据我所知,ѭ1用于在其父级中调用函数,该函数可能需要参数传递,在这种情况下构造函数需要数组传递...
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()
});
});
“ 3”表示使用参数config或此范围调用父级。
因此,Ext.component
中的onRender
功能会被your4ѭ覆盖...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。