PDA

View Full Version : Create a new TreePanel Node and Select it.



dwb
27 Feb 2012, 3:45 PM
Hello,

I've got a tree panel and I'm adding leaf nodes to it from the panel's controller.

Controller Code:

addEventRule: function(){
var content = Ext.getCmp('BillingPlanTreeCtn'); //wrapper
var win = Ext.getCmp('billplanwin'); //add event window
var createContainer = Ext.create('Nile.view.layout.BillingPlanTree'); //new instance of treepanel
var bpTree = Ext.getCmp('BillingPlanTree'); //get treepanel
var infoMsg = Ext.getCmp('infoMsg'); //default user message
var bpCombox = Ext.getCmp('BillPlanCombox'); //event rule combox
var taskTxt = bpCombox.getValue(); //event-type txt


//if content is info message, remove this, replace with new treepanel
if(!infoMsg){


bpTree.getRootNode().appendChild({


task: taskTxt,
id: 'leaf-'+ i,
activeItem: true,
iconCls: 'iconEventRuleSet',
leaf: true,

});
win.destroy(); //bye win

}
//else kill info msg, add blank treepanel & kill win


else{

content.removeAll(true);
//new event rule node
bpTree.getRootNode().appendChild({

task: taskTxt,
id: 'leaf-'+ i,
iconCls: 'iconEventRuleSet',
leaf: true

});

content.add(createContainer);
createContainer.doLayout();
createContainer.show();
win.destroy();


};

bpTree.getView().select(0);
//works when 1st new node is added.
//additional nodes cause error: Cannot call method 'getAt' of undefined
}

Anyone know how to make the last leaf created to be selected? With the arrangement above, I get the first node to be selected, but, all following node additions result in an error: Cannot call method 'getAt' of undefined

vietits
27 Feb 2012, 5:04 PM
I have simulated your case by creating a tree, appending child nodes to it then selecting the last node and everything worked well without error. I am not sure what causes the problem with your code, however, let try by fixing your code as follow (in red color):


...
var node;
if(!infoMsg){
node = bpTree.getRootNode().appendChild({
task: taskTxt,
id: 'leaf-'+ i,
activeItem: true,
iconCls: 'iconEventRuleSet',
leaf: true,
});
win.destroy(); //bye win
}
//else kill info msg, add blank treepanel & kill win
else{
content.removeAll(true);
//new event rule node
node = bpTree.getRootNode().appendChild({
task: taskTxt,
id: 'leaf-'+ i,
iconCls: 'iconEventRuleSet',
leaf: true
});
content.add(createContainer);
createContainer.doLayout();
createContainer.show();
win.destroy();
};
bpTree.getView().select(node);
...

dwb
28 Feb 2012, 8:40 AM
Hi vietits,

Thanks for the valent effort. I've introduced the changes your've shown me and now I'm receiving a different error: Cannot read property 'length' of undefined. Looks like Ext is having issues reading the length of the node array ... maybe? Or, has our Node var returned "undefined"? Or both? I'm baffled, but, I'm getting used to it - seems to be par for the Ext course.

Well, I'm checking that I've put in the correct "Required" configuration etc. and anything else I can think of.

Thanks again for this nugget of knowledge - I really appreciate you efforts.