Apache flex 如何通过actionscript创建flex树,并动态设置其数据提供程序
我想根据数据库中保存的存储创建一个树。我从数据库中获取所有存储,并通过操作脚本为每个存储生成树,还设置其数据提供程序 我的代码是:Apache flex 如何通过actionscript创建flex树,并动态设置其数据提供程序,apache-flex,tree,Apache Flex,Tree,我想根据数据库中保存的存储创建一个树。我从数据库中获取所有存储,并通过操作脚本为每个存储生成树,还设置其数据提供程序 我的代码是: var customTree:Tree=新树() customTree.showRoot=false customTree.labelField='label' customTree.dataProvider=xmlval;//xmlval是我的XML 当我运行应用程序时,它会按原样打印xml。但当我将树控件设置为静态,并且仅通过操作脚本设置其数据提供程序时,它就会
var customTree:Tree=新树()
customTree.showRoot=false
customTree.labelField='label'
customTree.dataProvider=xmlval;//xmlval是我的XML 当我运行应用程序时,它会按原样打印xml。但当我将树控件设置为静态,并且仅通过操作脚本设置其数据提供程序时,它就会正常工作。
请帮帮我。看看这个代码。我认为你应该用“@label”作为labelField,而不仅仅是“label”
);
私有函数init():void
{
var customTree1:Tree=新树();
customTree1.dataProvider=xml;
customTree1.labelField=“label”;
customTree1.width=200;
customTree1.height=300;
vgMain1.添加元素(自定义树1);
var customTree2:Tree=新树();
customTree2.dataProvider=xml;
customTree2.labelField=“@label”;
customTree2.width=200;
customTree2.height=300;
vgMain2.添加元素(customTree2);
}
]]>
您也可以发布MXML代码吗?
<?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" creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.controls.Tree;
[Bindable]private var xml:XML = new XML(
<item label="root">
<item label="Section A">
<item label="Section A.1"/>
<item label="Section A.2"/>
<item label="Section A.3"/>
</item>
<item label="Section B">
<item label="Section B.1"/>
<item label="Section B.2"/>
<item label="Section B.3"/>
</item>
</item>
);
private function init():void
{
var customTree1:Tree = new Tree();
customTree1.dataProvider = xml;
customTree1.labelField = "label";
customTree1.width = 200;
customTree1.height = 300;
vgMain1.addElement(customTree1);
var customTree2:Tree = new Tree();
customTree2.dataProvider = xml;
customTree2.labelField = "@label";
customTree2.width = 200;
customTree2.height = 300;
vgMain2.addElement(customTree2);
}
]]>
</fx:Script>
<s:HGroup top="20" left="20" width="600" height="300">
<s:VGroup width="200" height="100%">
<s:Label text="MXML Tree"/>
<mx:Tree dataProvider="{xml}" labelField="@label" width="100%" height="300"/>
</s:VGroup>
<s:VGroup id="vgMain1" width="200" height="100%">
<s:Label text="AS Tree with 'label'"/>
</s:VGroup>
<s:VGroup id="vgMain2" width="200" height="100%">
<s:Label text="AS Tree with '@label'"/>
</s:VGroup>
</s:HGroup>
</s:Application>