吕展辉

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1、从flex中发送请求后,利用<s:RemoteObject/>启用回调方法,类似于jQuery的post函数:

<fx:Declarations>
        <s:RemoteObject id="myService" destination="myService" endpoint="{this.parentApplication.contextRoot}/messagebroker/amf" showBusyCursor="true">
            <s:method name="query" result="queryHandler(event)"/>
        </s:RemoteObject>
    </fx:Declarations>

2、从后台向flex中传递的是一个ArrayList<VD101>,在flex中对应ArrayCollection类型,因为返回的有很多内容如:errorMessage等,因此,我把它们封装在一个对象中叫做:QueryResponse,在QueryResponse中要与后台的QueryResponse相对应,并在前台绑定如下:

[Bindable]
[RemoteClass(alias="com.QueryResponse")]
public class QueryResponse
{

   public var listVD101:ArrayCollection;

}

3、在flex中接收时,就是利用event.result得到传出的值,类似于jQuery中post函数中的data.xxx。

var queryResponse:Object = event.result;

4、然后就可以得到listVD101这个集合,绑定到DataGrid中就可以了,结构如下:

<s:DataGrid>

  <s:columns>
                <s:ArrayList>

        <s:GridColumn/>

5、我要选中一行数据,并得到这行数据。就得添加监听器,头部:creationComplete="moduleCreationCompleteHandler(event)"(进入页面就初始化的方法)

在函数里面添加选中监听器如(myDataGrid为上面<s:DataGrid/>的id):

private function moduleCreationCompleteHandler(event:FlexEvent):void
            {
                this.myDataGrid.addEventListener(GridSelectionEvent.SELECTION_CHANGE,onSelected);
            }

private function onSelected(event:GridSelectionEvent):void
            {
                this.vd101 = DataGrid(event.target).selectedItem as VD101;
            }

6.之后就得到了vd101的数据。

7、向jsp/servlet中传递字段(传递对象有点麻烦用到了)

var urlRequest:URLRequest = null;
                    urlRequest = new URLRequest(this.parentApplication.contextRoot + "/myServlet?d10101=" + this.vd101.d10101 + "&d10102=" + this.v1101.d10102);
                    navigateToURL(urlRequest,"_blank");

8、向另一个flex页面传值(可以和jsp中子页面(弹出框)和父页面这种关系传值相比较),在子页面中可以直接用了

public function myFunction(event:MouseEvent):void
            {
                if(this.vD101 == null){
                    Alert.show("请选择要操作的行");
                    return;
                }else{
                    var window:detial = new detial();
                    window.vd101 = this.vD101;
                    PopUpManager.addPopUp(window,this);
                    var x:Number = (this.parentApplication.mdiCanvas.width - window.width) / 2;
                    var y:Number = (this.parentApplication.mdiCanvas.height - window.height) / 2;
                    window.move(x, y);
                }
            }

9、从后台传过来的ArrayList类型转换为flex的ArrayCollection类型,取出其中一个对象

vd301 = listVD301.getItemAt(0) as VD301;使用as强制转换(即,显示转变),

posted on 2014-04-17 10:14  吕展辉  阅读(371)  评论(0编辑  收藏  举报