1

我有一个绑定到可编辑 DataGrid 的 ArrayCollection,另一个组件需要知道 ArrayCollection 何时更改(由于 DataGrid 中的更改),因此它也可以更新自身,因此监听 ArrayCollection 的 COLLECTION_CHANGE 事件。

问题是 DataGrid 仅在正在编辑的行失去焦点时更新 ArrayCollection。这对我的应用程序不利,因为用户可以编辑一行上的列,而不是长时间单击表格上的其他位置(导致该行失去焦点),因此更改不会传播到其他部分应用程序。

每当文本输入上出现 keyup 事件而不是每次一行失去焦点时,如何让数据网格通知 ArrayCollection 更改?

干杯,

克里斯

4

2 回答 2

1

我会将处理程序添加到用于编辑值的组件而不是 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);"
于 2010-02-21T03:48:24.957 回答
0

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

  <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 事件。

于 2010-02-21T05:01:11.887 回答