请检查以下fiddle。我有一个名为Grand Parent
的节点,此节点有两个子节点:Child Node
& Child Two
。
当用户点击Grand Parent节点时,我想直到层次结构中的最后一个节点并更新每个节点中的一个属性。
点击Grand Parent
节点后,我可以访问Child Node
& Child two
节点,但我找不到他们的孩子。
有什么方法可以找到层次结构中的每个子节点。
答案 0 :(得分:1)
您可以使用'cascade'
方法来实现此目的。 (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.container.AbstractContainer-method-cascade)
喜欢这个小提琴http://jsfiddle.net/j27rfzu6/1/
var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [{
text: "Grand Parent",
checked: false,
isSelected: false,
id: '1',
children: [{
text: 'Child Node',
checked: false,
IsSelected: false,
id: '1.1',
children: [{
text: "Grand Child One",
expanded: true,
checked: false,
isSelected: false,
id: '1.1.1',
}, {
text: "Grand Child Two",
expanded: true,
checked: false,
isSelected: false,
id: '1.1.2',
}, {
text: "Grand Child Three",
expanded: true,
checked: false,
isSelected: false,
id: '1.1.3',
}]
}, {
text: 'Child Two',
checked: false,
isSelected: false,
id: '1.2',
children: [{
text: "Grand Child Four",
expanded: true,
checked: false,
isSelected: false,
id: '1.2.1',
}]
}]
}]
}
});
Ext.create('Ext.tree.Panel', {
title: 'Example Tree',
width: 200,
height: 450,
store: store,
rootVisible: false,
multiSelect: true,
renderTo: Ext.getBody(),
listeners: {
itemclick: function (thisGrid, record, item, index, e, eOpts) {
record.cascade( function(){
alert(this.get('text'));
});
var v = 10;
alert('clicked');
}
}
});