- llying
- 等级: 初级会员
- 性别:
- 文章: 45
- 积分: 30
- 来自: 长春
|
FLEX处理返回的数据,然后绑定有很多种方法.不过看牛人们一般都是对数据进行处理成对象,再绑定到数据集.可能是这样更符合面向对象,也更合乎规范。用JSON对那些牛人来讲可能是方便不少,数据条理也相对清晰很多.
xml 代码
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute"
- creationComplete="service.send()">
-
- <mx:Script>
- <![CDATA[
- import mx.collections.ArrayCollection;
- import mx.rpc.events.ResultEvent;
- import com.adobe.serialization.json.JSON;
-
- private function onJSONLoad(event:ResultEvent):void
- {
- //get the raw JSON data and cast to String
- var rawData:String = String(event.result);
-
- //decode the data to ActionScript using the JSON API
- //in this case, the JSON data is a serialize Array of Objects.
- var arr:Array = (JSON.decode(rawData) as Array);
-
- //create a new ArrayCollection passing the de-serialized Array
- //ArrayCollections work better as DataProviders, as they can
- //be watched for changes.
- var dp:ArrayCollection = new ArrayCollection(arr);
-
- //pass the ArrayCollection to the DataGrid as its dataProvider.
- grid.dataProvider = dp;
-
- }
- ]]>
- </mx:Script>
-
- <mx:HTTPService id="service" resultFormat="text"
- url="http://weblogs.macromedia.com/mesh/mashedpotato.json"
- result="onJSONLoad(event)" />
-
- <mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10">
- <mx:columns>
- <mx:DataGridColumn headerText="Service" dataField="src"/>
- <mx:DataGridColumn headerText="Title" dataField="title"/>
- </mx:columns>
- </mx:DataGrid>
- </mx:Application>
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|