Flex4 DataGrid添加CheckBox及动态添加数据
发布时间:2020-12-15 04:15:29 所属栏目:百科 来源:网络整理
导读:?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"s:layouts:VerticalLayout//s:layo
<?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"> <s:layout> <s:VerticalLayout/> </s:layout> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.events.FlexEvent; [Bindable] public var arr:ArrayCollection = new ArrayCollection([{id:1,name:"芒果",count:1000,selected:"true"},{id:2,name:"香蕉",count:2120,selected:"false"},{id:3,name:"苹果",count:3000,name:"桔子",selected:"false"}]); protected function button1_clickHandler(event:MouseEvent):void { var o:Object = new Object(); o.name = "aaa"; o.count = 1122; o.selected = "true"; arr.addItem(o); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <s:Button label="添加数据" click="button1_clickHandler(event)"/> <s:DataGrid dataProvider="{arr}" width="400" height="300"> <s:columns> <s:ArrayList> <s:GridColumn headerText="序号" dataField="id" editable="false" /> <s:GridColumn headerText="名称" dataField="name" editable="false"/> <s:GridColumn headerText="数量" dataField="count" editable="false"/> <s:GridColumn> <s:itemRenderer> <fx:Component> <s:GridItemRenderer> <fx:Script> <![CDATA[ protected function getSelected(s:String):Boolean//防止有滚动条时显示异常 { if(s == "true") { return true; } return false; } ]]> </fx:Script> <s:CheckBox selected="{getSelected(data.selected)}"/> </s:GridItemRenderer> </fx:Component> </s:itemRenderer> </s:GridColumn> </s:ArrayList> </s:columns> </s:DataGrid> </s:Application> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |