Flex DataGrid之一(定义数据源直接赋值)
1.第一种在datagrid组件中直接赋值。<mx:DataGrid x="210" y="184" dataProvider="{myDP}">
<?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:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] private var myDP:ArrayCollection = new ArrayCollection([ {Artist:'Pavement', Album:'Slanted and Enchanted', Price:'(11.99)'}, {Artist:'Pavement', Album:'Crooked Rain, Crooked Rain', Price:'(10.99)'}, {Artist:'Pavement', Album:'Wowee Zowee', Price:'(12.99)'}, {Artist:'Pavement', Album:'Brighten the Corners', Price:'(11.99)'}, {Artist:'Pavement', Album:'Terror Twilight', Price:'(11.99)'} ]); ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <mx:DataGrid x="210" y="184" dataProvider="{myDP}"> <mx:columns> <mx:DataGridColumn headerText="Artist" dataField="Artist"/> <mx:DataGridColumn headerText="Album" dataField="Album"/> <mx:DataGridColumn headerText="Price" dataField="Price"/> </mx:columns> </mx:DataGrid> </s:Application>
2.第二种赋值方式:datagrid.dataProvider=myDP;
<?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" initialize="init()" > <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; [Bindable] private var myDP:ArrayCollection = new ArrayCollection([ {Artist:'Pavement', Album:'Slanted and Enchanted', Price:'(11.99)'}, {Artist:'Pavement', Album:'Crooked Rain, Crooked Rain', Price:'(10.99)'}, {Artist:'Pavement', Album:'Wowee Zowee', Price:'(12.99)'}, {Artist:'Pavement', Album:'Brighten the Corners', Price:'(11.99)'}, {Artist:'Pavement', Album:'Terror Twilight', Price:'(11.99)'} ]); function init(){ datagrid.dataProvider=myDP; } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <mx:DataGrid x="210" y="184" id="datagrid" > <mx:columns> <mx:DataGridColumn headerText="Artist" dataField="Artist"/> <mx:DataGridColumn headerText="Album" dataField="Album"/> <mx:DataGridColumn headerText="Price" dataField="Price"/> </mx:columns> </mx:DataGrid> </s:Application>
相关推荐
yangkang 2020-11-09
lbyd0 2020-11-17
sushuanglei 2020-11-12
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gaobudong 2020-11-04
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30