我創建了一個顯示樹形控件的mxml頁面,但數據僅顯示爲分支。即使是葉子的項目也被顯示爲分支。我究竟做錯了什麼?請幫忙!Flex樹形控件只顯示分支元素而不是葉元素
感謝, 音
<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>
你說得對。我將其更改爲xml.section.length()> 0。 – toneb 2010-09-29 03:22:16