首先直接传送Arraycollection到后台是,后台不能获取Arraycollection的各种数据。只有在后台将其转换为IList<T>泛型来 操作。
一定要注意,生成的类在NEW时一定要将所有的属性都赋值。
1.现在Flex中编写类,如下:
package source.Model { import mx.charts.DateTimeAxis; //此句不能少,用于对应服务端对象,将对象进行序列化 //规则: 命名空间.类名 [RemoteClass(alias="ServiceLibrary.aa")] public class aa { public function aa(label:String,id:String) { _label = label; _id = id; } private var _label:String; public function get label():String { return _label; } public function set label(value:String):void { _label = value; } private var _id:String; public function get id():String { return _id; } public function set id(value:String):void { _id = value; } } }
2.在.net后台建相对于的类
using System; using System.Collections.Generic; using System.Text; namespace ServiceLibrary { public class aa { private string _label; public string label { get { return _label; } set { _label = value; } } private string _id; public string id { get { return _id; } set { _id = value; } } } }
3.在flex中建立Arraycollection并传送到后台:
var CustomersList1:ArrayCollection = new ArrayCollection(); CustomersList1.addItem(new aa("xiaoming","01")); CustomersList1.addItem(new aa("zou","01")); Service.getArrayCollection(CustomersList1);
4.在后天将接受到的Arraycollection转换为IList<aa>:
public string getArrayCollection(ArrayCollection cc) { IList<aa> accoutList; accoutList = (cc.List).OfType<aa>().ToList(); return accoutList[0].label; }
5.接下来就是C#的分内事情了。