2011-12-12 19 views
1

當我編輯網格的最後一行時,我的itemEditEnd事件方法被調用,但是我的ArrayCollection中的數據未被更新以反映所做的更改。所有其他列工作,只是最後一列似乎有問題。我不確定這是一個錯誤,還是我需要做一些不同的事情? (Flash Builder 4.5/Flex 4.5.1)Flex - DataGrid編輯 - 一個錯誤,或允許在數據網格中編輯的正確方法?

我有一個簡單的可編輯DataGrid ArrayCollection,因爲它是數據提供者。它填充和我可以編輯。我趕上了itemEditEnd事件,並從我的數組集合讓行傳回服務器:

public var _recs:ArrayCollection = new ArrayCollection; 

<mx:DataGrid id="recsDG" dataProvider="{_recs}" 
       editable="true" itemEditEnd="recsDG_itemEditEndHandler(event)"> 
     <mx:columns> 
      <mx:DataGridColumn headerText="id" dataField="id" editable="false"/> 
      <mx:DataGridColumn headerText="type" dataField="type"/> 
... more columns ... 
     </mx:columns> 
    </mx:DataGrid> 



protected function recsDG_itemEditEndHandler(event:DataGridEvent):void 
     { 
        // THIS IS MY ARRAY COLLECTION/ROW(?): _recs[event.rowIndex] 
      } 

如果我點擊到最後一列第二一次又一次改變它,我可以看到,值在數組集合中現在變成了我之前做的更改。例如,當調試器跟蹤,比如我的原始值是「AAA」時,我將它更改爲「BBB」並按Tab,在調試器的itemEditEnd中顯示「AAA」(僅適用於最後一列)。然後我將該值更改爲「CCC」和選項卡,並在調試器中看到「BBB」!

我也嘗試過'event.currentTarget.itemEditorInstance.data'屬性,並且它也沒有用鍵入的新值更新。

作爲一個臨時解決方案,我在網格末尾添加了一個可編輯列,沒有列標題,寬度爲1像素。這似乎工作,當我列出,現在它不再是最後一列,它似乎工作。儘管如此。

哦,我剛剛注意到,當我點擊時,他們都沒有更新,只有當我標籤!所以這是另一個問題?

回答

0

確保您的數據提供者標記爲[Bindable]。另外,請在您的itemEditEnd處理程序方法中嘗試_recs.refresh()。我在一個簡單的項目中設置了下面的代碼,它似乎工作正常(所有單元格在按Tab後立即更新數組集合)。另外,我正在使用Flex 4.5.1 SDK。如果這不能解決您的問題,您可以發佈您正在使用的完整代碼,還是提供可重現此問題的示例應用程序?

<?xml version="1.0" encoding="utf-8"?> 

</fx:Declarations> 

<fx:Script> 
    <![CDATA[ 
     import mx.collections.ArrayCollection; 
     import mx.events.DataGridEvent; 

     [Bindable] 
     public var _data:ArrayCollection = new ArrayCollection([ 
      {id:1,name:'Ted',pos:'Mgr'}, 
      {id:2,name:'Bob',pos:'Mgr'}, 
      {id:3,name:'Jeb',pos:'Mgr'} 
     ]); 

     protected function dg_itemEditEndHandler(event:DataGridEvent):void 
     { 
      _data.refresh(); 
     } 

    ]]> 
</fx:Script> 

<s:Panel title="Halo DataGrid Control Example" 
     width="75%" height="75%" 
     horizontalCenter="0" verticalCenter="0"> 
    <s:VGroup left="10" right="10" top="10" bottom="10"> 
     <s:Label width="100%" color="blue" 
       text="Select a row in the DataGrid control."/> 

     <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{_data}" editable="true" itemEditEnd="dg_itemEditEndHandler(event)"> 
      <mx:columns> 
       <mx:DataGridColumn dataField="id" headerText="ID"/> 
       <mx:DataGridColumn dataField="name" headerText="NAME"/> 
       <mx:DataGridColumn dataField="pos" headerText="POSITION"/> 
      </mx:columns> 
     </mx:DataGrid> 

     <mx:DataGrid id="dg2" width="100%" height="100%" rowCount="5" dataProvider="{_data}" editable="false" > 
      <mx:columns> 
       <mx:DataGridColumn dataField="id" headerText="ID"/> 
       <mx:DataGridColumn dataField="name" headerText="NAME"/> 
       <mx:DataGridColumn dataField="pos" headerText="POSITION"/> 
      </mx:columns> 
     </mx:DataGrid> 
    </s:VGroup> 
</s:Panel>