Flex的远程数据访问有几种方式:http service, web service, remote object。
其中remote object是跟Flex Data Services(FDS)配合使用的,而FDS是卖钱的,当然现在FDS的协议AMF有各种版本的开源实现,RoR社区也可以用WebORB for rails。remote object的好处不少,本身的效率高,使用者比较多,应用Value Object等概念的时候可以直接用Object。
不过既然是与Restful API交互,使用http service更加直接。返回的结果直接存成e4x格式,方便操作。
直接在ModelLocator中存储e4x对象,而不是VO。
需要数据绑定时,先把e4x对象绑到XMLListCollection上,然后再绑到其他地方。
代码差不多是这样:
<mx:httpservice url="http://www.dev.com:3000/accounts.xml" id="accountTransService"><mx:xmllistcollection source="{trans.tran}" id="xc"><mx:datagrid height="503" width="711" y="40" x="256" id="accountTransGrid">
</mx:datagrid></mx:xmllistcollection></mx:httpservice>
其中remote object是跟Flex Data Services(FDS)配合使用的,而FDS是卖钱的,当然现在FDS的协议AMF有各种版本的开源实现,RoR社区也可以用WebORB for rails。remote object的好处不少,本身的效率高,使用者比较多,应用Value Object等概念的时候可以直接用Object。
不过既然是与Restful API交互,使用http service更加直接。返回的结果直接存成e4x格式,方便操作。
直接在ModelLocator中存储e4x对象,而不是VO。
需要数据绑定时,先把e4x对象绑到XMLListCollection上,然后再绑到其他地方。
代码差不多是这样:
<mx:httpservice url="http://www.dev.com:3000/accounts.xml" id="accountTransService"><mx:xmllistcollection source="{trans.tran}" id="xc"><mx:datagrid height="503" width="711" y="40" x="256" id="accountTransGrid">
xml 代码
- <mx:HTTPService id="accountTransService" url="http://www.dev.com:3000/accounts.xml"
- resultFormat="e4x" useProxy="false" method="GET" result="accountTransResultHandler(event)"/>
- <mx:XMLListCollection id="xc" source="{trans.tran}"/>
- <mx:DataGrid id="accountTransGrid" x="256" y="40" width="711" height="503">
- <mx:dataProvider>
- {xc}
- </mx:dataProvider>
- </mx:DataGrid>
</mx:datagrid></mx:xmllistcollection></mx:httpservice>