How to select a node in Tree based on XML node property?
I have a tree im my mxml that uses a XMLListCo开发者_如何学JAVAllection as dataProvider. It´s XML is like:
<list>
<conta nome="Plano de Contas" id="1">
<conta nome="Creditos" id="2" />
<conta nome="Vendas" id="4" />
<conta nome="Juros" id="5" />
<conta nome="Debitos" id="3" />
</conta>
</list>
How can I make the node for, say, id==4 visible AND selected?
Thank you.
var xml:XML =
<list>
<conta nome="Plano de Contas" id="1">
<conta nome="Creditos" id="2" />
<conta nome="Vendas" id="4" />
<conta nome="Juros" id="5" />
<conta nome="Debitos" id="3" />
</conta>
</list>;
//find node conta with id=4 using xml selectors
var node:XML = xml.descendants("conta").(@id == 4)[0];
tree.selectedItem = node;
You might need to open node parents if they are not, mx:Tree might not do this automatically.
For selection you can use, this.myTree.selectedIndex=4, that done, it should become visible automatically.
精彩评论