flex ArrayCollection怎样去掉重复项
2个回答
展开全部
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="application1_creationCompleteHandler(event)"
minWidth="955" minHeight="600">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var ac:ArrayCollection = new ArrayCollection();
// init
ac.addItem("1");
ac.addItem("2");
ac.addItem("2");
ac.addItem("3");
var nac:ArrayCollection = new ArrayCollection();
// 循环放入新的arraycollection中,已经存在则不进行重新添加
for each(var item:String in ac)
{
if(nac.contains(item))
continue;
nac.addItem(item);
}
// 打印
for each(var nitem:String in nac)
{
trace(nitem);
}
}
]]>
</fx:Script>
</s:Application>
希望对楼主能有所帮助
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="application1_creationCompleteHandler(event)"
minWidth="955" minHeight="600">
<s:layout>
<s:BasicLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.FlexEvent;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var ac:ArrayCollection = new ArrayCollection();
// init
ac.addItem("1");
ac.addItem("2");
ac.addItem("2");
ac.addItem("3");
var nac:ArrayCollection = new ArrayCollection();
// 循环放入新的arraycollection中,已经存在则不进行重新添加
for each(var item:String in ac)
{
if(nac.contains(item))
continue;
nac.addItem(item);
}
// 打印
for each(var nitem:String in nac)
{
trace(nitem);
}
}
]]>
</fx:Script>
</s:Application>
希望对楼主能有所帮助
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码如下:
var ac:ArrayCollection = new ArrayCollection();
// init
ac.addItem("1");
ac.addItem("2");
ac.addItem("2");
ac.addItem("3");
var nac:ArrayCollection = new ArrayCollection();
// 循环放入新的arraycollection中,已经存在则不进行重新添加
for each(var item:String in ac)
{
if(nac.contains(item))
continue;
nac.addItem(item);
}
var ac:ArrayCollection = new ArrayCollection();
// init
ac.addItem("1");
ac.addItem("2");
ac.addItem("2");
ac.addItem("3");
var nac:ArrayCollection = new ArrayCollection();
// 循环放入新的arraycollection中,已经存在则不进行重新添加
for each(var item:String in ac)
{
if(nac.contains(item))
continue;
nac.addItem(item);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询