使用分层数据作为dataProvider时,AdvancedDataGrid中的项目编辑器出现问题

时间:2011-03-23 12:53:41

标签: flex hierarchical-data advanceddatagrid itemeditor

以下是示例代码。

当我在optionId列或选项列中开始编辑时,同一列的其他行也会受到影响并反映相同的值。但是当我在其他专栏编辑时它工作得很好...... 不知道原因。如果有人可以帮助我。

 <mx:AdvancedDataGrid id="electionGrid" width="100%" height="70%" folderOpenIcon="{null}" folderClosedIcon="{null}" defaultLeafIcon="{null}" editable="true">
        <mx:dataProvider>
            <mx:HierarchicalData source="{electionSummary}" childrenField="options"/>
        </mx:dataProvider>
        <mx:columns>
            <mx:AdvancedDataGridColumn dataField="dbProduct" headerText="DB Product" editable="false"/>             
            <mx:AdvancedDataGridColumn dataField="entitledQty" headerText="Entitled Quantity" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="entityId" headerText="Entity Id" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="entityName" headerText="Entity Name" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="eventStatus" headerText="Event Status" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="optionId" headerText="Option Id" itemEditor="mx.controls.TextInput" editorDataField="text"/>
            <mx:AdvancedDataGridColumn dataField="option" headerText="Description" itemEditor="mx.controls.TextInput" editorDataField="text"/>            
        </mx:columns>        
    </mx:AdvancedDataGrid>

Hiearchical Data:

 <mx:ArrayCollection id="optionData">
    <model:CAEventOption optionId="12345" option="Option1"/> 
    <model:CAEventOption optionId="56789" option="Option2"/>
    <model:CAEventOption optionId="89756" option="Option3"/>        
</mx:ArrayCollection>

<mx:ArrayCollection id="electionSummary">
    <model:ElectionStatusSummary dbProduct="Global PB" entitledQty="54500" entityId="DEM0001" entityName="Hedge Fund Long Short Period" 
                eventStatus="Awaiting Election" options="{new ArrayCollection(optionData.source)}"/>
    <model:ElectionStatusSummary dbProduct="Global PB" entitledQty="54500" entityId="DEM0001" entityName="Hedge Fund Long Short Period" 
                eventStatus="Awaiting Election" options="{new ArrayCollection(optionData.source)}"/>
    <model:ElectionStatusSummary dbProduct="Global PB" entitledQty="54500" entityId="DEM0001" entityName="Hedge Fund Long Short Period" 
                eventStatus="Awaiting Election" options="{new ArrayCollection(optionData.source)}"/>        
</mx:ArrayCollection>

1 个答案:

答案 0 :(得分:0)

{new ArrayCollection(optionData.source)}创建一个新的ArrayCollection。但是,基础Array始终是同一个对象(此处为optionData)。

为防止这种情况发生,您必须创建包含CAEventOption不同实例的三个不同数组。有点链接:

<mx:ArrayCollection id="electionSummary">
    <model:ElectionStatusSummary dbProduct="Global PB" entitledQty="54500" entityId="DEM0001"
                                 entityName="Hedge Fund Long Short Period" eventStatus="Awaiting Election">
        <model:options>
            <mx:ArrayCollection id="optionData">
                <model:CAEventOption optionId="12345" option="Option1"/>
                <model:CAEventOption optionId="56789" option="Option2"/>
                <model:CAEventOption optionId="89756" option="Option3"/>
            </mx:ArrayCollection>
        </model:options>
    </model:ElectionStatusSummary>
    <model:ElectionStatusSummary dbProduct="Global PB" entitledQty="54500" entityId="DEM0001"
                                 entityName="Hedge Fund Long Short Period" eventStatus="Awaiting Election">
        <model:options>
            <mx:ArrayCollection id="optionData">
                <model:CAEventOption optionId="12345" option="Option1"/>
                <model:CAEventOption optionId="56789" option="Option2"/>
                <model:CAEventOption optionId="89756" option="Option3"/>
            </mx:ArrayCollection>
        </model:options>
    </model:ElectionStatusSummary>
    <model:ElectionStatusSummary dbProduct="Global PB" entitledQty="54500" entityId="DEM0001"
                                 entityName="Hedge Fund Long Short Period" eventStatus="Awaiting Election">
        <model:options>
            <mx:ArrayCollection id="optionData">
                <model:CAEventOption optionId="12345" option="Option1"/>
                <model:CAEventOption optionId="56789" option="Option2"/>
                <model:CAEventOption optionId="89756" option="Option3"/>
            </mx:ArrayCollection>
        </model:options>
    </model:ElectionStatusSummary>
</mx:ArrayCollection>