PDA

View Full Version : How read parent tree node name in itemclick listener?



Michael710
12 Mar 2012, 7:40 PM
I have the following tree in an application. I am trying to read the parent node or leaf name when I click in the tree. alert(rec.get('text')) gives me the node name. how can you do something like:

alert(rec.get('parenttext'))

Thanks,

{title: 'Navigate',
height: 600,
width: 200,
x: 0,
y: 130,
listeners: {itemclick: function(node, rec, item, index, e) {alert(rec.get('text'));}},
store: Ext.create('Ext.data.TreeStore', {root: {expanded: true,children: [";.....

vietits
12 Mar 2012, 8:01 PM
What do you mean with node name or leaf name? Do you want to get the string shown on tree? If so, just use the followinging code:


listeners: {
itemclick: function(view, record, item, index, e) {
alert(record.get('text'));
},
...

Michael710
13 Mar 2012, 5:28 AM
I would like to read the parent node as well. My tree is dynamically rendered so I don't know what node the leaf belongs to. So in a tree like:

Node1
ChildA
ChildB
Node2
ChildC
ChildA

Suppose record.get('text') = ChildA. How do I know if it was click on the Node1 or Node2 Branch. Thanks,

vietits
13 Mar 2012, 5:43 AM
listeners: {
itemclick: function(view, node){
var parentNode = node.parentNode;
if(parentNode) {
alert(parentNode.get('text'));
}
},
...