Flex里DropDownList默认值记录

Flex的s:DropDownList标签。 
我们很多web的应用中,例如,修改操作,某些字段是用下拉框显示的,那么当你查询出来的值返回到页面时候,要根据所传来的值,显示相应的下拉的值,这个操作在flex有点特别,代码如下:

               //下拉框的数据集
public static var fileNameTypeDropDownList:ArrayCollection = new ArrayCollection([
			{id:0,label:'Flag文件'},
			{id:1,label:'固定文件名'},
			{id:2,label:'正则表达式'}
]);

//获取DropDownList选中元素的索引
public static function getSelectedIndexByResult(list:ArrayCollection, key:String, result:Object):int{
			var selectedIndex:int = 0;
			try{
				for(var i:int = 0; i<list.length; i++){
					if(list[i][key] == result){
						selectedIndex = i;
						break;
					}
				}
			}catch(e:Error){Alert.show(e.message);}
			return selectedIndex;
}

var index:int = this.getSelectedIndexByResult(fileNameTypeDropDownList,'id',data['file_name'])

//mxml使用
<s:DropDownList id="userGroupComboBox" selectedIndex={index} requireSelection="true" dataProvider="{fileNameTypeDropDownList}" labelField="USER_GROUP_NAME"/>

  


posted @ 2011-09-16 10:18  夏天的森林  阅读(5501)  评论(0编辑  收藏  举报