Flex 求两个ArrayCollection的交集

                           Flex 求两个ArrayCollection的交集

需求:已知两个ArrayCollection求交集

代码如下:

<?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" minWidth="955" minHeight="600">
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			
			public  var arrColl1:ArrayCollection = new ArrayCollection([{WellName:"1"},{WellName:"2"},{WellName:"3"}]);  //第一个集合
			public  var arrColl2:ArrayCollection = new ArrayCollection([{WellName:"2"},{WellName:"3"},{WellName:"4"}]); //第一个集合
			public  var arrOr:ArrayCollection = new ArrayCollection();     //用来存放arr1和arr2的交集
			
			public function OrOperator():void{
				//ArrayCollection的交操作
				for each(var obj:Object in arrColl1)
				{
					for each(var item:Object in arrColl2)
					{
						if(obj.WellName == item.WellName)
							arrOr.addItem(obj);
					}
				}		
				//打印出arrOr的值
				var str:String="";
				for(var i3:int=0;i3<arrOr.length;i3++)
				{
					str+=arrOr.getItemAt(i3).WellName;
				}
				Alert.show("str的值为:" + str);		
			}
			
		]]>
	</fx:Script>
	<s:Button x="187" y="166" width="109" height="38" label="调用函数" click="OrOperator();"/>
</s:Application>




你可能感兴趣的:(Flex 求两个ArrayCollection的交集)