- <?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>
很简单的JSON绑定Flex的Grid
最新推荐文章于 2018-03-14 18:26:46 发布
本文介绍了一种使用 Flex 的方法来从远程 URL 加载 JSON 数据,并将其解析为 ActionScript 对象的过程。通过将原始 JSON 数据转换为 ArrayCollection,进而设置 DataGrid 的 dataProvider 属性,实现了数据的有效展示。
190

被折叠的 条评论
为什么被折叠?



