不需要的绑定
情况很简单。我有一个从网络服务获取数据的数据网格。
当从 Web 服务检索数据时,它会调用以下函数:
private function onListReg():void
{
arrRegOld = WSAutoreg.list.lastResult as ArrayCollection;
arrReg = WSAutoreg.list.lastResult as ArrayCollection;
dgReg.dataProvider = autoreglist;
}
dgReg 是数据网格。 arr 变量是像这样定义的 ArrayCollections:
private var arrRegOld:ArrayCollection = new ArrayCollection;
[Bindable]
private var arrReg:ArrayCollection = new ArrayCollection;
目的是当我点击更新按钮时,它将 arrRegOld 与 arrReg 进行比较,看看是否有任何值发生变化。问题是每当我更改 Datagrid 上的值时,它都会在 dataProvider 和 ArrayCollections 上发生变化。
有谁知道为什么会发生这种情况?我应该怎么做才能使绑定仅适用于一个 ArrayCollection?
感谢任何提示。 - 迈克
The situation is simple. I have a datagrid that gets its data from a webservice.
When data from the webservice is retrived it calls the following function:
private function onListReg():void
{
arrRegOld = WSAutoreg.list.lastResult as ArrayCollection;
arrReg = WSAutoreg.list.lastResult as ArrayCollection;
dgReg.dataProvider = autoreglist;
}
dgReg is the Datagrid. the arr variables are ArrayCollections defined like so:
private var arrRegOld:ArrayCollection = new ArrayCollection;
[Bindable]
private var arrReg:ArrayCollection = new ArrayCollection;
The intent is when I hit a update button, it compares arrRegOld with arrReg and see if any values have changes. The problem is whenever I change values on the Datagrid it changes on both the dataProvider and on both ArrayCollections.
Does anyone know why is this happening? What should I do so that the binding applies only to one ArrayCollection?
Appreciate any tip.
- Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的列表共享相同的对象,如果您修改 arrReg 中的第一个元素,您也会在 arrRegOld 中看到修改 - 它与绑定无关。您需要克隆对象。您有多种选择:
a) 为您的对象实现克隆方法(推荐)
b) 使用像这样的通用方法:
并调用 arrRegOld = clone (arrReg); arrReg = WSAutoreg.list.lastResult as ArrayCollection 之后;
Your lists are sharing the same objects, if you modify the first element from arrReg you will see the modification also in arrRegOld - it is not related to binding. You need to clone the objects. You have several choices:
a) Implement a clone method for your objects (recommended)
b) Use a generic method like this one:
and call arrRegOld = clone (arrReg); after arrReg = WSAutoreg.list.lastResult as ArrayCollection;