内联 itemEditor

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
           
            [Bindable]
            private var ac1:ArrayCollection=new ArrayCollection([{id:001,name:"apple",price:10.0},
                {id:002,name:"orange",price:1.0},{id:003,name:"tea",price:30.0}]);
               
            [Bindable]
            private var ac2:ArrayCollection=new ArrayCollection([{id:001,name:"apple",fruit:true},
                {id:002,name:"orange",fruit:true},{id:003,name:"tea",fruit:false}]);
               
            private function checkHandler(item:Object,col:*):String{
                return item.fruit?"yes":"NO";
            }   
           
            [Bindable]
            private var ac3:ArrayCollection = new ArrayCollection(
            [ {account:"account1",  ccard:"1234100012341000"},
              {account:"account3", ccard:"0000222244441111"},
              {account:"account2", ccard:"9222833374446555"}
            ]);
           
           
        ]]>
    </mx:Script>
   
    <mx:VBox>
        <mx:HBox>
            <mx:DataGrid dataProvider="{ac1}" editable="true">
                <mx:columns>
                    <mx:DataGridColumn headerText="ID" dataField="id" editable="false"/>
                    <mx:DataGridColumn headerText="名称" dataField="name" editable="false"/>
                    <mx:DataGridColumn headerText="价格" dataField="price" editable="true"/>
                </mx:columns>
            </mx:DataGrid>
           
            <mx:DataGrid dataProvider="{ac1}" editable="true">
                <mx:columns>
                    <mx:DataGridColumn headerText="ID" dataField="id" editable="false"/>
                    <mx:DataGridColumn headerText="名称" dataField="name" editable="false"/>
                    <mx:DataGridColumn headerText="价格" dataField="price">
                        <mx:itemEditor>
                            <mx:Component>
                                <mx:TextInput restrict="0-9"/><!-- 输入为数字-->
                            </mx:Component>
                        </mx:itemEditor>
                    </mx:DataGridColumn>
                </mx:columns>
            </mx:DataGrid>
        </mx:HBox>
        <mx:HBox>
            <mx:DataGrid dataProvider="{ac1}" editable="true">
                <mx:columns>
                    <mx:DataGridColumn headerText="ID" dataField="id" editable="false"/>
                    <mx:DataGridColumn headerText="名称" dataField="name" editable="false"/>
                    <mx:DataGridColumn headerText="价格" dataField="price" itemEditor="mx.controls.NumericStepper" editorDataField="value"/>
                </mx:columns>
            </mx:DataGrid>
           
           
            <mx:DataGrid dataProvider="{ac2}" editable="true">
                <mx:columns>
                    <mx:DataGridColumn headerText="ID" dataField="id" editable="false"/>
                    <mx:DataGridColumn headerText="名称" dataField="name" editable="false"/>
                    <mx:DataGridColumn headerText="是不是水果?" dataField="fruit"
                        itemEditor="mx.controls.CheckBox" editorDataField="selected" labelFunction="checkHandler"/>
                </mx:columns>
            </mx:DataGrid>
        </mx:HBox>
        <mx:DataGrid dataProvider="{ac3}" editable="true" width="302">
                <mx:columns>
                    <mx:DataGridColumn headerText="account" dataField="account" editable="false" width="100"/>
                    <mx:DataGridColumn headerText="ccard" dataField="ccard" editorDataField="value">
                        <mx:itemEditor>
                            <mx:Component>
                                <mx:HBox>
                                    <mx:Script>
                                    <![CDATA[
                                        public function get value():String{
                                            return p1.text+p2.text+p3.text+p4.text;
                                        }
                                        override public function set data(value:Object):void{
                                            super.data=value;
                                            p1.text=value.ccard.substr(0,4);
                                            p2.text=value.ccard.substr(4,4);
                                            p3.text=value.ccard.substr(8,4);
                                            p4.text=value.ccard.substr(12,4);
                                        }
                                    ]]>
                                </mx:Script>
                                <mx:TextInput id="p1" maxChars="4" restrict="[0-9]" width="40"/>
                                <mx:TextInput id="p2" maxChars="4" restrict="[0-9]" width="40"/>
                                <mx:TextInput id="p3" maxChars="4" restrict="[0-9]" width="40"/>
                                <mx:TextInput id="p4" maxChars="4" restrict="[0-9]" width="40"/>
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemEditor>
                    </mx:DataGridColumn>
                </mx:columns>
            </mx:DataGrid>
    </mx:VBox>
</mx:Application>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值