1

我有一个 ArrayCollection,我想删除所有空值或空值。

代码中的哪一行可以做到这一点?

4

1 回答 1

1

就性能而言,这是更快的方法:

<mx:Script><![CDATA[
    public function cleanArrayCollection(collection:ArrayCollection):ArrayCollection{
        var currentArray:Array = null;    
        var newCollection:ArrayCollection = new ArrayCollection();
        for(var i:int = 0; i < collection.length; i++){
            currentArray = collection.getItemAt(i);
            if(currentArray != null && currentArray.length != 0){
                newCollection.addItem(currentArray);
            }
        }

        return newCollection;
    }
]]></mx:Script>

编辑:删除了逻辑中的关键错误。

于 2011-04-26T20:30:48.003 回答