首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

匹配已选中数据的某字段和上拉框数据

2012-11-03 
匹配已选中数据的某字段和下拉框数据package YD.Web.Common.Utils{import mx.collections.ArrayCollection

匹配已选中数据的某字段和下拉框数据

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');

热点排行