PDA

View Full Version : Problem when loading a model



jedihua
16 Oct 2010, 12:08 PM
In my code I created a panel with a form. I use initcomponent to create the form and a button below the form. The next thing I want to do is whenever I click the button (use listener)I want to load a model to fill the blanks, and it seems that there is no way to call the loadModel function inside the initComponent function, since the form object hasnt been created yet. Can anyone give me some help? Thanks

Stoot98
16 Oct 2010, 12:39 PM
Try putting your loadModel code in an afterrender listener.




this.on('afterrender', function(){
//do loadModel
}, this);

jedihua
16 Oct 2010, 12:49 PM
Thanks for the reply. The thing is that I want to load the model only when I click the button, and the button is part of the form. What I'm doing now is I add a listener to the button and I put the loadmodel code in the listener. So where should I put this part of code? Thanks!

Stoot98
16 Oct 2010, 12:54 PM
If you want to do the loadModel in the button listener then by that time the form will exist so it should be alright. Post some code and I can get a better picture of the problem.

jedihua
16 Oct 2010, 7:26 PM
The code is:


SetupPanel = Ext.extend(Ext.form.FormPanel, {
layout: {
align: 'stretch'
},
scroll: 'vertical',

initComponent: function() {
this.items = [{
xtype: 'fieldset',
title: 'Server Setup',
instructions: 'Please Select the Default Server',
items: [{
xtype: 'select',
name: 'servername',
label: 'Server Name',
valueField: 'serverid',
displayField: 'servername',
store: setupStore,
listeners: {
select: function (f, r, i) {
var snameGiven = setupStore.data.items[r].data.servername;
var sadrGiven = setupStore.data.items[r].data.serveraddress;
var susnGiven = setupStore.data.items[r].data.username;

user = Ext.ModelMgr.create({
'servername': snameGiven,
'serveraddress': sadrGiven,
'username': susnGiven
}, 'ServerSetup');
// call loadModel
this.loadModel(user);


}
}
}]
},{
// rest fields and buttons
}];

CA.SetupPanel.superclass.initComponent.call(this);
}

});

I use the listener to check which one is selected in the dropdown menu, and I want to load certain information for different selections.