http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/
Displaying the number of children in each branch of a Flex Tree control
The following example shows how you can display the number of children in each branch of a Tree control in Flex by using the dataDescriptor property, labelFunction property, hasChildren() method and getChildren() method.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/01/11/displaying-the-number-of-children-in-each-branch-of-a-flex-tree-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
private function tree_labelFunc(item:XML):String {
var label:String = item.@label;
if (tree.dataDescriptor.hasChildren(item)) {
label += " (" + tree.dataDescriptor.getChildren(item).length + ")";
}
return label;
}
]]>
</mx:Script>
<mx:XML id="treeDP">
<root>
<node label="i) One" />
<node label="i) Two" />
<node label="i) Three" />
<node label="i) Four">
<node label="ii) One" />
<node label="ii) Two" />
<node label="ii) Three">
<node label="iii) One" />
<node label="iii) Two" />
</node>
<node label="ii) Four" />
</node>
<node label="1. Five" />
<node label="1. Six" />
</root>
</mx:XML>
<mx:Tree id="tree"
dataProvider="{treeDP}"
labelFunction="tree_labelFunc"
showRoot="false"
width="200" />
</mx:Application>
本文介绍如何使用Flex的Tree控件显示每个分支的子项数量。通过dataDescriptor属性、labelFunction属性、hasChildren()方法及getChildren()方法实现。提供了完整的MXML代码示例。

1万+

被折叠的 条评论
为什么被折叠?



