Flex:如何更改绑定到数据网格的ArrayCollection实时?

问题描述:

我有一个ArrayCollection绑定到可编辑的DataGrid,另一个组件需要知道ArrayCollection何时更改(由于DataGrid中的更改),因此它也可以自行更新,因此正在侦听ArrayCollection的COLLECTION_CHANGE事件。Flex:如何更改绑定到数据网格的ArrayCollection实时?

问题是DataGrid只在被编辑的行丢失焦点时更新ArrayCollection。这对我的应用程序并不好,因为用户可以编辑一行中的一列,而且不会长时间点击表格中的其他位置(导致行失去焦线),因此这些更改不会传播到其他部分应用程序。

如何在每次在文本输入中存在关键事件而不是每次行失去焦点时让数据网格通知ArrayCollection每次发生更改?

干杯,

克里斯

我会处理程序添加到用于编辑的价值,而不是到ArrayCollection的组件。例如:

<mx:DataGridColumn dataField="name" headerText="Name" itemEditor="{nameEditor}" editorDataField="selectedItem" /> 

然后这被用来编辑该值:

<mx:Component id="nameEditor"> 
    <mx:ComboBox dataProvider="{outerDocument.names}" change="outerDocument.setNameField(event)" close="outerDocument.setNameField(event)" /> 
</mx:Component> 

而这是用于改变(和关闭)事件处理程序:

public function setDestinationField(event:*):void { 
    var destination:String = (event.target as ComboBox).selectedLabel; 
    if (destination === '') { 
     delete _gridData[_currentlyEditedRowIndex].destination; 
    } else { 
     _gridData[_currentlyEditedRowIndex].destination = destination; 
    } 
} 

_currentlyEditedRowIndex由设置将此添加到网格中:

itemEditBegin="beginEdit(event);" 

谢谢加百列你让我走在正确的道路上。我将在这里发布我的最终解决方案,以防其他人在未来需要做同样的事情。

<mx:DataGridColumn headerText="Title" width="300" dataField="title"> 
    <mx:itemEditor> 
     <mx:Component> 
     <mx:TextInput change="data.title = text" /> 
     </mx:Component> 
    </mx:itemEditor> 
    </mx:DataGridColumn> 

现在,每当文本ArrayCollection中被用作数据提供程序中输入更改也会被更新,所以其他组件监听COLLECTION_CHANGE事件。