如果有人遇到同样的问题,我会在这里留下我的解决方案。
我能做的最好的事情 - 创建扩展列表控件,每次更新集合时都会自行刷新。因此,基于火花列表创建新控件并在此处添加以下代码:
<fx:Script>
<![CDATA[
import mx.collections.IList;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;
/**
* Subscribe to collection change event.
*/
override public function set dataProvider(value:IList):void
{
if (dataProvider)
dataProvider.removeEventListener(CollectionEvent.COLLECTION_CHANGE,
dataProvider_collectionChangeHandler);
if (value)
value.addEventListener(CollectionEvent.COLLECTION_CHANGE, _collectionChangeHandler, false, 0, true);
var _itemRenderer:IFactory = this.itemRenderer;
this.itemRenderer = null;
this.itemRenderer = _itemRenderer;
super.dataProvider = value;
}
/**
* If collection has changed - redraw list by resetting itemRenderer.
*/
private function _collectionChangeHandler(event:Event):void
{
if (event is CollectionEvent)
{
var ce:CollectionEvent = CollectionEvent(event);
// We don't need to refresh if any collection element will change.
if(ce.kind != CollectionEventKind.UPDATE)
{
var _itemRenderer:IFactory = this.itemRenderer;
this.itemRenderer = null;
this.itemRenderer = _itemRenderer;
}
}
}
]]>
</fx:Script>