【问题标题】:Flex CheckBox in Datagrid数据网格中的 Flex CheckBox
【发布时间】:2009-07-13 17:13:24
【问题描述】:
在以下弹性代码中: 也可以在以下位置查看:http://www.cse.epicenterlabs.com/checkBoxDg/checkBoxDg.html 1.通过单击“AddRow”在数据网格中添加一行 2. 点击“CheckDg”查看所有复选框的值 - 它显示“checkBox57”或“checkBox64”或一些类似的字符串 3. 现在,“选择”第一行中的复选框。 4.再次点击“CheckDg” - 它显示“真实” 所以,最初 dp.getItemAt(i).date 返回一个 CheckBox 然后它返回 CheckBox 的“选定”值? 为什么会有这种差异?
<?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>

【问题讨论】:

    标签: apache-flex datagrid checkbox


    【解决方案1】:

    您不应该将对象分配给数据变量而是数据。 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] :-)

    【讨论】:

      【解决方案2】:

      当您单击网格中的复选框时,它会将“true”或“false”写入日期字段,替换原来的 CheckBox 对象。我相信 itemEditors(您将渲染用作编辑器)所做的是将 .data 属性从各个组件写入集合中。

      【讨论】:

        【解决方案3】:

        将该特定数据网格列的“可编辑”属性设置为 false。这将解决问题

        【讨论】:

          猜你喜欢
          • 2010-12-28
          • 2011-07-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-10
          • 2011-12-07
          • 2011-09-07
          相关资源
          最近更新 更多