Showing 1 - 1 of 1 total. RSS Feed WordPress RSS Feed

Edit multiple items in sorted ArrayCollection

Do following if you want to traverse through sorted ArrayCollection, update multiple items and trigger only one collection change event to optimize performance of components that use the collection.
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
var collection:ArrayCollection = new ArrayCollection();

collection.addItem({bar:"bar1", foo:1});
collection.addItem({bar:"bar2", foo:2});
collection.addItem({bar:"bar3", foo:3});
collection.addItem({bar:"bar4", foo:4});

var sort:Sort = new Sort();
sort.fields = [new SortField("foo")];

collection.sort = sort;
collection.refresh();

collection.addEventListener(CollectionEvent.COLLECTION_CHANGE, function(e:CollectionEvent):void {

trace(e.type);

});

collection.disableAutoUpdate();

var cursor:IViewCursor = collection.createCursor();

while (!cursor.afterLast) {

cursor.current.foo++;

cursor.view.itemUpdated(cursor.current);

cursor.moveNext();

}

collection.enableAutoUpdate();
Showing 1 - 1 of 1 total. RSS Feed WordPress RSS Feed