我正在使用 SparkTree (4.0) 组件 ( http://kachurovskiy.com/2010/spark-tree/ ),因为我遇到了 mx:Tree 组件的一些问题。
我有一个 xml 数据,我将其转换为 xmllistcollection 并分配给 SparkTree 组件的 dataprovider 属性。它没有正确渲染。后来,在阅读了针对 SparkTree 组件发布的几个常见问题解答后,我意识到该树对于 arraycollection 而不是 xml/xmllist/xmlcollection 的表现非常理想。
因此,我将 xml 数据转换为 arraycollection 并将其分配给 SparkTree 的 dataprovider。尽管如此,只有顶级节点显示为叶节点,不显示子节点。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600"
xmlns:sparkTree="com.sparkTree.*" >
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
import mx.events.FlexEvent;
import mx.rpc.xml.SimpleXMLDecoder;
import mx.utils.ArrayUtil;
[Bindable]
private var dlist:XMLListCollection;
[Bindable]
private var dColln:ArrayCollection;
[Bindable]
private var dashColln:ArrayCollection;
[Bindable]
private var dashListColln:ArrayCollection;
protected function sparkTree_creationCompleteHandler(event:FlexEvent):void
{
var dashList:XMLList=XMLList(testxml.children());
var mydecoder:SimpleXMLDecoder=new SimpleXMLDecoder();
var data:Object=mydecoder.decodeXML(new XMLDocument(dashList.toXMLString()));
dashListColln = new ArrayCollection();
if (data != null && data.menu.length > 0) {
for (var i:int=0; i<data.menu.length; i++) {
dashColln = new ArrayCollection(Array(data.menu[i]));
dashListColln.addAll(dashColln);
}
}
}
]]>
</fx:Script>
<fx:Declarations>
<fx:XML id="testxml" source="xml/Test.xml" />
</fx:Declarations>
<s:Panel width="75%" height="75%" horizontalCenter="0" verticalCenter="0">
<sparkTree:Tree id="sparkTree"
dataProvider="{dashListColln}"
creationComplete="sparkTree_creationCompleteHandler(event)"
width="100%"
height="100%"
textRollOverColor="yellow"
textSelectedColor="0xFFFFFF" dragEnabled="true" dropEnabled="true"
dragMoveEnabled="true">
<!--<sparkTree:layout>
<s:TileLayout horizontalGap="0" verticalGap="0" orientation="columns"/>
</sparkTree:layout>-->
</sparkTree:Tree>
</s:Panel>
</s:Application>
`
<root>
<menu label="A">
<menu label="A1">
<menu label="A1.1" />
</menu>
<menu label="A2" >
<menu label="A2.2"/>
</menu>
<menu label="A3" >
<menu label="A3.3"/>
</menu>
<menu label="A4" >
<menu label="A4.4"/>
</menu>
</menu>
<menu label="B">
<menu label="B1" />
<menu label="B2" />
<menu label="B3" />
</menu>
<menu label="C">
<menu label="C1" />
<menu label="C2" />
<menu label="C3" />
</menu>
<menu label="D">
<menu label="D1" />
<menu label="D2" />
</menu>
<menu label="E">
<menu label="E1" />
</menu>
</root>
请分享您对此的想法。为什么即使 arraycollection 有子对象我也没有得到子节点?