数据网格中的Flex复选框控件

时间:2011-12-14 06:01:05

标签: flex actionscript datagrid flex3

在我的flex应用程序中使用的数据网格有 checkbox itemrenderer列 即时通讯使用以下代码

<mx:DataGridColumn headerText="Select"  dataField="isSelect" editable="false" textAlign="center"   >
                        <mx:itemRenderer >
                            <mx:Component>

                                <mx:CheckBox  selected="{data.isSelect}" change="outerDocument.addDetail(data)"  > 
                                </mx:CheckBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:DataGridColumn>

                    <mx:DataGridColumn headerText="FirstName" dataField="firstName" color="black" editable="false" width="125" />
                    <mx:DataGridColumn headerText="SecondName" dataField="lsecondName" color="black" editable="false" width="125"/>

选中复选框并保存我的数据库中的详细信息。 现在, 当我来获取数据时,应在复选框中选择数据库中选定的详细信息。 我如何区分选定的记录和未选择的记录。提前超过

2 个答案:

答案 0 :(得分:1)

<mx:itemRenderer>
                        <mx:Component>
                            <mx:HBox horizontalAlign="center" verticalAlign="middle">
                                <mx:Script>
                                    <![CDATA[
                                        var objTemp:Object = new Object();

                                        override public function set data(value:Object):void
                                        {
                                            if(value != null)
                                            {
                                                var xml:XML = XML(value);
                                                super.data = value;
                                                objTemp = outerDocument.xmlToObject(xml.toString());
                                                if(objTemp.story['quiz_score'] != null)
                                                {
                                                    chkAssignment.visible = false;
                                                }
                                                else
                                                {
                                                    chkAssignment.visible = true;
                                                }
                                                if(objTemp.story.is_selected == false)
                                                {
                                                    chkAssignment.selected = false;
                                                }
                                                else
                                                {
                                                    chkAssignment.selected = true;
                                                }

                                            }
                                        }

                                        private function deleteAssignment():void
                                        {


                                            if(chkAssignment.selected)
                                            {
                                                outerDocument.isChanged = true;

                                                objTemp.story.is_selected = true;
                                                var xml:XML = outerDocument.objectToXML(objTemp,"record");

                                                var xmlList:XMLList = xml.children();
                                                xml = xmlList[0] as XML;

                                                outerDocument.dgListeningLog.dataProvider[outerDocument.dgListeningLog.selectedIndex] = xml;

                                                outerDocument.arrAssignment.push({"story_name": XML(outerDocument.dgListeningLog.selectedItem).story_title.toString() ,"student_assignmentId": XML(outerDocument.dgListeningLog.selectedItem).assignment_id.toString(),"session_key": XML(outerDocument.dgListeningLog.selectedItem).session_key.toString(),"selectedIndex": outerDocument.dgListeningLog.selectedIndex.toString()});
                                            }
                                            else
                                            {
                                                outerDocument.isChanged = true;

                                                objTemp.story.is_selected = false;
                                                var xml:XML = outerDocument.objectToXML(objTemp,"record");

                                                var xmlList:XMLList = xml.children();
                                                xml = xmlList[0] as XML;

                                                outerDocument.dgListeningLog.dataProvider[outerDocument.dgListeningLog.selectedIndex] = xml;

                                                for(var i:int =0; i < outerDocument.arrAssignment.length; i++)
                                                {
                                                    if(outerDocument.arrAssignment[i].selectedIndex == outerDocument.dgListeningLog.selectedIndex)
                                                    {
                                                        outerDocument.arrAssignment.splice(i,1);
                                                        break;
                                                    }
                                                }
                                            } 

                                        }

                                    ]]>
                                </mx:Script>
                                <mx:CheckBox id="chkAssignment" change="{deleteAssignment();}"/>
                            </mx:HBox>
                        </mx:Component>
                    </mx:itemRenderer>

这里我将选定的值或数组存储在另一个数组中,当单击“删除”按钮时,它将检查并删除作为dataGrid的数据提供者的主数组中的值。

如果您在滚动数据网格时遇到问题CheckBox显示的错误值比从代码中复制以下方法错误:

覆盖公共函数集数据(value:Object):void

答案 1 :(得分:0)

您确定,行itemRenderer提供的data是否具有正确的isSelect属性?试着trace