Ex_Soft
9 Feb 2012, 7:39 AM
Method# 1
Ext.define("CustomPanel", {
extend: "Ext.panel.Panel",
alias : "widget.custompanel",
constructor: function(config) {
config = config || {};
Ext.applyIf(config, {
buttons: [
{
text: "Button# 1"
}
]
});
this.listeners = config.listeners;
this.callParent([config]);
this.addListener("beforeadd", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforeadd(%o)", arguments);
});
return this;
},
initComponent: function() {
Ext.apply(this, {
tbar: {
items: [
{
xtype: "button",
text: "TBar Button #1 (Add)",
handler: function(btn, e) {
this.add({ xtype: "button", text: "AddedButton" });
},
scope: this
}
]
}
});
this.addListener("afterrender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.afterrender(%o)", arguments);
});
this.callParent(arguments);
this.addListener("beforerender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforerender(%o)", arguments);
});
}
});
Ext.onReady(function() {
var
p = Ext.create("CustomPanel", {
border: 50,
renderTo: Ext.getBody(),
listeners: {
render: function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.render(%o)", arguments);
}
}
});
});
works fine.
Method# 2
Ext.define("CustomPanel", {
extend: "Ext.panel.Panel",
alias : "widget.custompanel",
config: {
buttons: [
{
text: "Button# 1"
}
],
listeners: {
beforeadd: function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforeadd(%o)", arguments);
}
}
},
constructor: function(config) {
this.initConfig(config);
this.callParent([this.config]);
return this;
},
initComponent: function() {
Ext.apply(this, {
tbar: {
items: [
{
xtype: "button",
text: "TBar Button #1 (Add)",
handler: function(btn, e) {
this.add({ xtype: "button", text: "AddedButton" });
},
scope: this
}
]
}
});
this.addListener("afterrender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.afterrender(%o)", arguments);
});
this.callParent(arguments);
this.addListener("beforerender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforerender(%o)", arguments);
});
}
});
Ext.onReady(function() {
var
p = Ext.create("CustomPanel", {
border: 50,
renderTo: Ext.getBody(),
listeners: {
render: function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.render(%o)", arguments);
}
}
});
});
render() -> initContainer() -> El.get(el) (ext-all-debug.js line# 7929) returns null for renderTo. Why? What is the difference between method# 1 and method# 2?
P.S. This is a test code. I've read this (http://www.sencha.com/forum/showthread.php?124740-constructor-or-initComponent) and I understand that the best way is to use initComponent.
Ext.define("CustomPanel", {
extend: "Ext.panel.Panel",
alias : "widget.custompanel",
constructor: function(config) {
config = config || {};
Ext.applyIf(config, {
buttons: [
{
text: "Button# 1"
}
]
});
this.listeners = config.listeners;
this.callParent([config]);
this.addListener("beforeadd", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforeadd(%o)", arguments);
});
return this;
},
initComponent: function() {
Ext.apply(this, {
tbar: {
items: [
{
xtype: "button",
text: "TBar Button #1 (Add)",
handler: function(btn, e) {
this.add({ xtype: "button", text: "AddedButton" });
},
scope: this
}
]
}
});
this.addListener("afterrender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.afterrender(%o)", arguments);
});
this.callParent(arguments);
this.addListener("beforerender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforerender(%o)", arguments);
});
}
});
Ext.onReady(function() {
var
p = Ext.create("CustomPanel", {
border: 50,
renderTo: Ext.getBody(),
listeners: {
render: function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.render(%o)", arguments);
}
}
});
});
works fine.
Method# 2
Ext.define("CustomPanel", {
extend: "Ext.panel.Panel",
alias : "widget.custompanel",
config: {
buttons: [
{
text: "Button# 1"
}
],
listeners: {
beforeadd: function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforeadd(%o)", arguments);
}
}
},
constructor: function(config) {
this.initConfig(config);
this.callParent([this.config]);
return this;
},
initComponent: function() {
Ext.apply(this, {
tbar: {
items: [
{
xtype: "button",
text: "TBar Button #1 (Add)",
handler: function(btn, e) {
this.add({ xtype: "button", text: "AddedButton" });
},
scope: this
}
]
}
});
this.addListener("afterrender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.afterrender(%o)", arguments);
});
this.callParent(arguments);
this.addListener("beforerender", function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.beforerender(%o)", arguments);
});
}
});
Ext.onReady(function() {
var
p = Ext.create("CustomPanel", {
border: 50,
renderTo: Ext.getBody(),
listeners: {
render: function(panel, eOpts) {
if(window.console && console.log)
console.log("CustomPanel.render(%o)", arguments);
}
}
});
});
render() -> initContainer() -> El.get(el) (ext-all-debug.js line# 7929) returns null for renderTo. Why? What is the difference between method# 1 and method# 2?
P.S. This is a test code. I've read this (http://www.sencha.com/forum/showthread.php?124740-constructor-or-initComponent) and I understand that the best way is to use initComponent.