PDA

View Full Version : How do i get a value from child node in tree?



EXTDEV007
13 Feb 2014, 9:42 PM
I built my tree using a for loop and using .push()
It has children with different values.

{text:"Audi"; Door: "2", model:"A5"}
{text:"Audi"; Door: "4", model:"A6"}

How do we get the value of child node(Door)? I was able to get Audi using record.data.text,

How can i loop through the childnodes and get the different models or different doors? I need to do some matching in the forloop

Thanks

mdnaveed42
13 Feb 2014, 10:21 PM
Hi,

Sample code for you..


var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [{
text: "Audi 5",
leaf: true,
Door: "2",
model: "A5"
}, {
text: "Audi 6",
leaf: true,
Door: "4",
model: "A6"
}]
}
});


Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
itemId: 'treePanel',
store: store,
rootVisible: false,
renderTo: Ext.getBody(),
listeners: {
itemClick: function(treeview, record, item, index, evt) {
// on first item click
console.log(record.raw.model); // "A5"
console.log(record.raw.Door); // "2"
}
}
});


This should work for you :)
Thanks,
Md Naveed
\m/

mdnaveed42
18 Feb 2014, 5:53 AM
Hi,

Did my code worked for you?
If yes, please mark it as Answered.

Thanks,
Md Naveed

pwiggins@cedarcreek.com
18 Feb 2014, 6:08 AM
I'm running into a similar issue. Can you do this with Select Event Bind?

mdnaveed42
19 Feb 2014, 3:08 AM
Hi,

Just change the itemClick event with select event, following is the sample code..


var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [{
text: "Audi 5",
leaf: true,
Door: "2",
model: "A5"
}, {
text: "Audi 6",
leaf: true,
Door: "4",
model: "A6"
}]
}
});


Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
itemId: 'treePanel',
store: store,
rootVisible: false,
renderTo: Ext.getBody(),
listeners: {
select: function(treeview, record, item, index, evt) {
// on first item click
console.log(record.raw.model); // "A5"
console.log(record.raw.Door); // "2"
}
}
});



Thanks,
Md Naveed
\m/

pwiggins@cedarcreek.com
19 Feb 2014, 7:21 AM
if I try to do console.log(record.raw.model) or in my case console.log(record.raw.name) and try to alert it, it alerts as undefined.

mdnaveed42
19 Feb 2014, 9:57 PM
Could you please share the code to look into the issue..