Flex怎样将数据库的信息读取到Tree控件中,请大侠,高手,大牛们帮忙解答谢谢!
后台C#写的WebServices的代码是:
前台Flex代码是:
<?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">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
<mx:WebService id="WebServiceTest"
wsdl="http://localhost/wenling/Service.asmx?WSDL"
useProxy="false"
fault="Alert.show(event.fault.faultString),'出错了'"
result="onResult(event)">
<mx:operation name="getConnection"/>
</mx:WebService>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
[Bindable]
public var arr:XML = new XML(); //定义一个变量用来接收数据
public var isSucceed:Boolean = new Boolean(false); //定义一个变量用来判断是否登录成功
private function init():void{
//把信息封装起来
var strSQL:String = "SELECT Name FROM SysObjects Where XType='U' and Name like 'A%' and len(Name)=7 order by Name";
//调用WebService里自定义的方法getConnection(string sql);
this.WebServiceTest.getConnection(strSQL);
}
private function onResult(event:ResultEvent):void{
arr= XML(event.result);
this.mytree.dataProvider = arr;
}
private function tree_change(event:Event):void{
var str:String = mytree.selectedItem.@label;
Alert.show(str);
}
]]>
</fx:Script>
<mx:Tree x="55" y="10" height="268" width="164" id="mytree"
change="tree_change(event)" creationComplete="init();" >
</mx:Tree>
</s:Application>
WebServices获取的信息是:
程序运行的效果是:
tree flex 数据库 webservice application
[解决办法]
你的Tree控件,labelField属性没设置吧