开发环境eclipse+java+BlazeDS
我现在查询查询一个表的数据方法是:
第一步:新建一个Module,里面的内容如下
- XML code
<mx:Module initialize="init()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="100%" height="100%"> <mx:DataGrid headerHeight="24" rowHeight="28" dataProvider="{roles}" width="100%" verticalAlign="middle" height="100%" headerStyleName="trHead"> <mx:columns> <mx:DataGridColumn width="180" dataField="name" headerText="角色代码" /> <mx:DataGridColumn width="80" dataField="roleType" headerText="角色类别" labelFunction="disRoleType" /> </mx:columns> </mx:DataGrid> </mx:Module>
第二步:添加一个remoteObject
- XML code
<mx:RemoteObject id="krSysRoleService" destination="flexKrSysRoleService" result="getRole(event)" showBusyCursor="true"/>
第三步:写查询代码
- XML code
private function init():void{ krSysRoleService.query(); } private function getRole(event:ResultEvent):void{ roles = ArrayCollection(event.result); }
按上面的步骤可以吧数据查询出来,并且显示在DataGrid里面,问题是我现在想把上面查询的代码放在一个Class/as文件里面,直接写一个方法,将我的值直接返回出来,然后在我的Module里面写一个方法,把值绑定在DataGrid,用上面的方法只能是先写init()方法放在initialize里面,然后再去根据事件返回值去处理roles = ArrayCollection(event.result);,希望大侠给段代码指点一下。。谢谢。。
------解决方案--------------------
新建一个 public class Service extends RemoteObject
将配置赋值,并有静态方法引用
- Java code
public class Service extends RemoteObject { public static var _service:Service; public static function get service():Service { return _service; } public static function configService(destination:String,endpoint:String,source:String):void { _service = new Serivce(destination,endpoint,source); } public static function getOperation(name:String,responder:IResponder):Object { var operation:AbstractOperation = _service.getOperation(name); operation.addEventListener(ResultEvent.RESULT,responder.result); operation.addEventListener(FaultEvent.FAULT,responder.fault); return operation; } public function Service(destination:String,endpoint:String,source:String) { super(destination); this.endpoint = endpoint; this.source = source; } }
------解决方案--------------------
对了,主代码中需要查询时实例化KrSysRoleDelegate,然后krSysRoleDelegate.getRole()即可,krSysRoleDelegate可以设置相关侦听ResultEvent.RESUL/FaultEvent.FAULT
------解决方案--------------------
学习了
------解决方案--------------------
楼上的老大,谢谢了,,我看了看, 还看的不是很明白
------解决方案--------------------
楼上的老大,谢谢了,,我看了看, 还看的不是很明白
------解决方案--------------------
------解决方案--------------------
Flex中可以使用:
1、
- XML code