我有一个从arraycollection 扩展的对象。该对象必须访问和操作 arraycollections 源对象。发生这种情况时,数据的本地排序/过滤副本与源数据不同步。要正确排列,需要重新应用排序/过滤器。
要正常执行此操作,您将在 arraycollection 上调用 refresh(),但这也会广播一个刷新事件。我想要的是在不调度事件的情况下更新排序/过滤器。
查看 ArrayCollection 类后,我可以看到它是从 ListCollectionView 扩展而来的。刷新功能
public function refresh():Boolean
{
return internalRefresh(true);
}
在 ListCollectionView 中,它调用了这个函数
private function internalRefresh(dispatch:Boolean):Boolean
{
if (sort || filterFunction != null)
{
try
{
populateLocalIndex();
}
catch(pending:ItemPendingError)
{
pending.addResponder(new ItemResponder(
function(data:Object, token:Object = null):void
{
internalRefresh(dispatch);
},
function(info:Object, token:Object = null):void
{
//no-op
}));
return false;
}
if (filterFunction != null)
{
var tmp:Array = [];
var len:int = localIndex.length;
for (var i:int = 0; i < len; i++)
{
var item:Object = localIndex[i];
if (filterFunction(item))
{
tmp.push(item);
}
}
localIndex = tmp;
}
if (sort)
{
sort.sort(localIndex);
dispatch = true;
}
}
else if (localIndex)
{
localIndex = null;
}
revision++;
pendingUpdates = null;
if (dispatch)
{
var refreshEvent:CollectionEvent =
new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
refreshEvent.kind = CollectionEventKind.REFRESH;
dispatchEvent(refreshEvent);
}
return true;
}
烦人的是,该函数是私有的,因此不能用于扩展 ListCollectionView 的类。此外,internalRefresh 函数中的很多内容也是私有的。
有谁知道从扩展 ArrayCollection 的类中调用 internalRefresh 的方法?或者在调用刷新时停止发送刷新事件的方法?