ComBox和DataGrid显示 ArrayCollection数据的基本操作
效果图:
代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var c:ArrayCollection=new ArrayCollection([{label:"aaa"},{label:"bbb"},{label:"ccc"},{label:"ddd"}]);
[Bindable]
private var d:ArrayCollection=new ArrayCollection([{id:"1",name:"张三",age:"20"},{id:"2",name:"李四",age:"21"},
{id:"3",name:"王五",age:"30"},{id:"4",name:"小军",age:"32"}]);
]]>
</fx:Script>
<s:ComboBox x="210" y="88" dataProvider="{c}"/>
<s:DataGrid x="364" y="88" width="231" height="137" dataProvider="{d}" requestedRowCount="4">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="id" headerText="id"></s:GridColumn>
<s:GridColumn dataField="name" headerText="name"></s:GridColumn>
<s:GridColumn dataField="age" headerText="age"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
</s:Application>