選択したデータに一致するフィールドとドロップダウン・ボックスのデータ

1331 ワード


package YD.Web.Common.Utils
{
	import mx.collections.ArrayCollection;

	public class DataAnalysis
	{
		public function DataAnalysis()
		{
		}
		
		/**
		 *  , , <br/>
		 * data:  ,ArrayCollection XML<br/>
		 * label:  <br/>
		 * property:  Object XML , , , 
		 **/
		public static function listDataMatching(data:Object,label:String,property:String=null):int
		{
			if(data is ArrayCollection)
			{
				var ac:ArrayCollection = data as ArrayCollection;
				for(var i:int=0;i<ac.length;i++)
				{
					if(property)
					{
						if(label == ac[i][property])
							return i;
					}
					else
					{
						if(label == ac[i].toString())
							return i;
					}
				}
			}
			else if(data is XML)
			{
				var xml:XML = data as XML;
				for each(var j:XML in xml.*)
				{
					if(label == j.@[property])
						return j.childIndex();
				}
			}
			return -1;
		}
	}
}

使用例:

pStateDDL.selectedIndex = DataAnalysis.listDataMatching(productionStateAC,o.productionState,'name');