在Flex中使用相同地址创建的两个对象
问题描述:
我在flex中遇到了一个问题,它引起了一些头痛!在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提出的解决方案?
答
咨询上述提到的后线程我解决这样问题:
我的代码载列于另一个类,像这样:
model.index.rows = model.index.holdRows;
这似乎在整个代码中传播。相反,我将此行更改为:
model.index.rows = new ArrayCollection(model.index.holdRows.source.concat());
如提及的线程中所述。这为我删除了重复的条目! :o)
非常感谢你的帮助! – James 2010-05-20 10:48:19
没问题,几个月前有同样的问题,你可以看到也在这里解决:) – Ladislav 2010-05-20 11:01:45