Iterate over ArrayCollection when adding or removing items

I want to iterate over an ArrayCollection in Flex, while elements can be added and removed.

Since I have not found a way to use the "classic" Iterator, as in Java, which would do the job. I tried the cursor. But this does not work the way I want it to be;) So, how do I do it beautifully?


    var cursor:IViewCursor = workingStack.createCursor();

    while (!cursor.afterLast)
    {
        // Search
                    deepFirstSearchModified(cursor.current.node,nodeB,cursor.current.way);
        // Delete Node
        cursor.remove();
        // Next Node
        cursor.moveNext();

    }
+3
source share
5 answers

I think it's better to use New Collection / Array for operations as

private function parseSelectedItem(value:IListViewCollection):IListViewCollection{
 var result:Array = new Array();
    for each(var item:Object in value)
    {
        //result.push();
        //result.pop();
    }
    return new ArrayCollection(result) ;
}

Hopes that help

+3
source

Try using the following:

for (var i:int = myArrayCollection.length - 1; i >= 0; i--) {
   myArrayCollection.removeItemAt(i);
}
+2
source

Take a look at ActionLinq . It implements the .Net Linq2Objects template, including IEnumerable. Of course you need to be careful because you are changing the elements that you are repeating ...

var workingStack:ArrayCollection = getData();
var iterator:IEnumerable = Enumerable.from(workingStack);

for each(var item:String in iterator) {
  doSomethingTo(workingStack);
}
0
source

In flex (or actionscript), any change you make is displayed instantly. Therefore, you can do what you want to:

    for (var i : Number = myArrayCollection.length; i > 0; i--) {
       myArrayCollection.removeItemAt(i - 1);
    }

I think this should work fine.

-1
source

All Articles