【发布时间】:2011-04-16 13:10:21
【问题描述】:
我创建了一个显示树控件的 mxml 页面,但是数据仅显示为分支。即使是叶子的项目也显示为分支。我究竟做错了什么?请帮忙!
谢谢, 音调
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
public function init():void {
var item:Object;
var array:Array = new Array();
var xml:XML =
<course>
<section>
<title>Introduction to Actionscript</title>
<section>
<title>Lesson 1: Variables</title>
<section>
<title>Topic 1: Data types</title>
</section>
</section>
</section>
</course>;
item = parseStructure(xml);
array.push(item);
var arrColl:ArrayCollection = new ArrayCollection(array);
Tree.dataProvider = arrColl;
}
private function parseStructure(xml:XML):Object{
var obj:Object = new Object();
obj.label = xml.title;
if(xml.section != null) {
obj.children = new ArrayCollection();
for each (var child:XML in xml.section) {
obj.children.addItem(parseStructure(child));
}
}
return obj;
}
]]>
</mx:Script>
<mx:HBox>
<mx:Tree id="Tree" width="300"/>
</mx:HBox>
【问题讨论】:
标签: apache-flex flash