PDA

View Full Version : Writing an extension I got onRender error



crysfel
15 Feb 2010, 11:26 AM
Hi folks!

I'm writting a basic extension, just for testing :) I know about the component life cycle, all I want to do is to print a message into the firebug console in each phase but I'm getting the error: "b is undefined" only when I implement the "onRender" method, if I remove this method from my code the extension works fine.

here is my code:



Ext.ns("com.mycompany.testing");

com.mycompany.testing.PostPanel = Ext.extend(Ext.Panel,{
layout : "fit",
collapsible : true,
border : false,
params : {},

initComponent : function(){

console.debug("The init phase");

this.addEvents({
"loadPosts" : true,
"addPost" : true,
"removePost": true
});

this.store = new Ext.data.JsonStore({
autoDestroy : true,
url : this.url,
root : "data",
idProperty : "id",
fields : ["title","status","content",{name:"creation",type:"date",dateFormat:"Y-m-d h:i:s"}]
});
this.store.on("load",this.onLoadPosts,this);

com.mycompany.testing.PostPanel.superclass.initComponent.call(this);
},

onRender : function(){
console.debug("rendering phase");

com.mycompany.testing.PostPanel.superclass.onRender.call(this);
},

onDestroy : function(){
this.store.destroy();
this.grid.destroy();

com.mycompany.testing.PostPanel.superclass.onDestroy.call(this);

console.debug("destroy phase!");
},

onLoadPosts : function(){
console.debug("custom method");

this.fireEvent("loadPosts",this.store);
}

});


here is how I use the extension:



com.mycompany.testing.Core = {
init : function(){
var posts = new com.mycompany.testing.PostPanel({height:300,url:"find-data.php"});

var win = new Ext.Window({
title : "Posts",
layout : "fit",
tbar : [{text:"Load data",handler:function(){posts.store.load()}}],
width : 400,
height : 300,
items : [posts]
});

win.show();

posts.on("loadPosts",function(store){
Ext.Msg.alert("Loaded","Records loaded!");
})
}
}

Ext.onReady(com.mycompany.testing.Core.init,com.mycompany.testing.Core);


any help? thanks in advance :)

crysfel
15 Feb 2010, 11:32 AM
I just fix it :)

The onRender method recibe two parameters, thats all :)


onRender : function(container,position){
console.debug("rendering phase");

Quizz.training.PostPanel.superclass.onRender.call(this,container,position);
},


have fun everyone :)