apache-flex - Datagrid 中的 Flex CheckBox

标签 apache-flex datagrid checkbox

In the followin flex Code : 
Also viewable at : http://www.cse.epicenterlabs.com/checkBoxDg/checkBoxDg.html
1. Add a row in datagrid by clicking on "AddRow"
2. Click on "CheckDg" to see the values of all the checkboxes
     - it shows "checkBox57" or "checkBox64" or some similar string
3. Now, "select" the checkBox in the first row.
4. Click again on "CheckDg"
    -it show "true"

So, initially dp.getItemAt(i).date returns a CheckBox
and later it returns the "selected" value of the CheckBox?
Why this difference?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html">
        <mx:Canvas>
        <mx:DataGrid x="69" y="119" id="dgFee" editable="true" dataProvider="{dp}">
            <mx:columns>
            <mx:DataGridColumn headerText="Date" dataField="date" width="100" editable="true" 
            editorDataField="selected" rendererIsEditor="true">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:CheckBox selected="false">
                                       </mx:CheckBox>
                        </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
                       <mx:DataGridColumn dataField="amount" headerText="Amount" editable="true">
                         <mx:itemEditor>
                         <mx:Component>
                                  <mx:TextInput restrict="0-9"/>
                         </mx:Component>
                         </mx:itemEditor>   
                       </mx:DataGridColumn>
            </mx:columns>
        </mx:DataGrid>
        <mx:CheckBox x="130" y="54" label="Checkbox" selected="true" click="Alert.show(abc.selected.toString())" id="abc"/>
<mx:Script>
    <![CDATA[
        import mx.controls.CheckBox;
        import mx.collections.ArrayCollection;
        import mx.controls.Alert;
        public var dp:ArrayCollection = new ArrayCollection();
        public function addRow():void
        {
          var tmp:Object = new Object();
          tmp['amount'] = 100;
          tmp['date'] = new CheckBox();
          dp.addItem(tmp);
        }
        public function delRow():void
        {
            if(dgFee.selectedIndex != -1)
            dp.removeItemAt(dgFee.selectedIndex);
        }

        public function loop1():void
        {
            for(var i:int=0;i<dp.length;i++)
            {
               Alert.show(dp.getItemAt(i).date);
            }
        }
    ]]>
</mx:Script>
                <mx:Button x="29" y="89" label="AddRow" click="addRow()"/>
                <mx:Button x="107" y="89" label="DelRow" click="delRow()"/>
                <mx:Button x="184" y="89" label="CheckDg" click="loop1()"/>

</mx:Canvas>    
</mx:Application>

最佳答案

您不应该将对象分配给数据变量,而是数据。 Checkbox.select 属性首先设置为您的复选框对象,然后在上述操作之后设置为 true 或 false。试试这个吧

public function addRow():void
{
  var tmp:Object = new Object();
  tmp['amount'] = 100;
  tmp['date'] = false; // not new CheckBox();
  dp.addItem(tmp);
}

PS:dp 也应该归因于 [Bindable] :-)

关于apache-flex - Datagrid 中的 Flex CheckBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1120841/

相关文章:

java - 在集群环境中实现 Flex 身份验证/授权有何不同?

cakephp - 从表中删除多个选定项目

android - 使复选框在 Android 中看起来已禁用

arrays - 原始声音 byteArray 到 float Array

apache-flex - Flex - 保持客户端数据与后端数据库同步的最佳策略?

actionscript-3 - 试图理解一个函数

wpf - WPF DataGrid 中缺少边框线 (125%) 显示

c# - 在 Datagridview 中分组

css - Dojo DataGrid autoHeight 在 IE9 中不工作

Android 溢出菜单复选框颜色