我在flex中有一个问题,这引起了一些麻烦!
我正在向ArrayCollection添加对象,但是这样做,即使没有绑定发生,另一个ArrayCollection也会拾取这些更改。
我可以从调试中看到两个AC具有相同的地址,但对于我的生活无法弄清楚原因。
我有两个数组集合:
model.index.rows //The main array collection
model.index.holdRows //The array collection that imitates the above
这个幻像数据绑定仅在循环中的第一次迭代中发生,对于所有其他的,它只会将其写入一次。
这引起麻烦的原因是它在我的数据网格中创建了重复的条目。
public override function handleMessage(message:IMessage):void
{
super.handleMessage(message);
if (message is IndexResponse)
{
var response:IndexResponse = message as IndexResponse;
model.index.rows.removeAll();
model.index.indexIsEmpty = response.nullIndex;
if (model.index.indexIsEmpty !== true)
{
//Update the index model from the response. Note: each property of the row object will be shown in the UI as a column in the grid
response.index.forEach(function(entry:EntryData, i:int, a:Array):void
{
var row:Object = { fileID: entry.fileID, dadName: entry.dadName };
entry.tags.forEach(function(tag:Tag, i:int, a:Array):void
{
row[tag.name] = tag.value;
});
model.index.rows.addItem(row);
});
if(model.index.indexForNetworkView == true){
model.index.holdRows.source = model.index.holdRows.source.concat(model.index.rows.source);
model.index.indexCounter++;
model.index.indexForNetworkView = false;
controller.indexController.showNetwork(model.index.indexCounter);
}
model.index.rows.refresh();
controller.networkController.show();
}
}
有没有其他遇到过simillar的人提出解决方案?
答案 0 :(得分:0)
我在这个stackoverflow线程中问了同样的问题,它解释了发生了什么,你能做些什么来解决它:
Changes to one variable propagates to another
的Ladislav
答案 1 :(得分:0)
在咨询上述线程后,我解决了这个问题:
我在其他类中设置了代码,如下所示:
model.index.rows = model.index.holdRows;
这似乎在整个代码中传播。相反,我将此行更改为:
model.index.rows = new ArrayCollection(model.index.holdRows.source.concat());
如提到的帖子中所示。这为我删除了重复的条目! :O)