上次不能显示班级数据的问题,从表格中使用一个方法来读取:
private function labFun(item:Object,col:DataGridColumn):String{ return item.classes.id.toString(); } 如果需要,可以将此数据转换为其它值。在表格的列中使用:
<mx:DataGridColumn headerText="班级" dataField="classes" labelFunction="labFun"/>
这样在显示数据时,将显示班级的ID。
//-----------------------------------------------
新建一个组件User.mxml,作为一个窗口进行数据的新增及修改:
代码:
<?xml version="1.0" encoding="utf-8"?> <mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="304" height="246" title="信息" creationComplete="this.getCombo()"> <mx:Script> <![CDATA[ import mx.rpc.remoting.RemoteObject; import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; import mx.managers.PopUpManager; private function closeBtn():void{ PopUpManager.removePopUp(this); } private function okBtn():void{ dispatchEvent(new Event("b1")); } //显示库中的班级数据 private function getCombo():void{ var obj:RemoteObject = new RemoteObject("GetClasses"); obj.addEventListener(ResultEvent.RESULT, rOk); obj.GetAll(); } private function rOk(evt:ResultEvent):void{ this._bj.dataProvider = evt.result as ArrayCollection; } ]]> </mx:Script> <mx:Form x="10" y="10"> <mx:FormItem label="姓名"> <mx:TextInput id="_xm"/> </mx:FormItem> <mx:FormItem label="年龄"> <mx:TextInput id="_nl"/> </mx:FormItem> <mx:FormItem label="家庭住址"> <mx:TextInput id="_jtzz"/> </mx:FormItem> <mx:FormItem label="班级"> <mx:ComboBox id="_bj" labelField="classname"></mx:ComboBox> </mx:FormItem> <mx:FormItem> <mx:HDividedBox width="100%"> <mx:Button label="确定" click="this.okBtn()"/> <mx:Button label="关闭" click="this.closeBtn();"/> </mx:HDividedBox> </mx:FormItem> </mx:Form> </mx:TitleWindow>