flex使用java列表数据创建datagrid

1、java list-》flex arrayCollection

java:

//第一种:返回对象列表
public List<Conf> getConfList(){
		List<Conf> list = new ArrayList<Conf>();
		for(int i = 0; i < 5; i++){
			Conf conf = new Conf();
			conf.setConfId(i);
			conf.setConfMsg("mes" + i);
			conf.setConfName("name" + 1);
			list.add(conf);
		}
		return list;
}

//第二种:返回map列表

public List<Map<String, String>> getConfList2(){
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		for(int i = 0; i < 5; i++){
			Map<String, String> map = new HashMap<String, String>();
			map.put("confId", "" + (i + 1));
			map.put("confName", "name" + (i + 1));
			list.add(map);
		}
		return list;
}

as:

将java的list转成ArrayCollection

public function confListHandle(listEvent:ResultEvent):void{
	var result:ArrayCollection = listEvent.result as ArrayCollection;
//	Alert.show(":" + result[0].confName);
 	dictGrid.dataProvider = result;
}

 mxml:

<!--列表-->
	<mx:DataGrid id="dictGrid" x="169" y="119" width="100%" height="100%" variableRowHeight="true">
		<mx:columns>
			<mx:DataGridColumn headerText="序号" dataField="confId" width="50" textAlign="center"/>
			<mx:DataGridColumn headerText="名称" dataField="confName" width="190" wordWrap="true"/>
			<mx:DataGridColumn headerText="操作" width="50">
				<mx:itemRenderer>
					<mx:Component>
						<mx:HBox>
							<mx:Script>
							<![CDATA[
								import mx.events.CloseEvent;
								import mx.collections.ArrayCollection;
								import mx.controls.Alert;
								
								Alert.okLabel = "确定";
								Alert.cancelLabel = "取消";
								private function delDriver( e:Event) : void{
									Alert.show("确定删除吗?","删除资源驱动",Alert.OK|Alert.CANCEL,null,
										function(e:CloseEvent):void{
									    if(e.detail == Alert.OK)
									    {
									    	//文件key
//									        var fileKey : String=outerDocument.dictGrid.selectedItem.newName;
									        //调用方法,删除数据库记录
//											outerDocument.dictRemote.delDict(fileKey);
									    }
									    else if(e.detail == Alert.CANCEL)
									    {
									        Alert.CANCEL;
									    }
									});
								}
							]]>
							</mx:Script>
							<mx:Spacer />
							<mx:LinkButton label="删除" click="delDriver(event)"></mx:LinkButton>
						</mx:HBox>
					</mx:Component>
				</mx:itemRenderer>
			</mx:DataGridColumn>
		</mx:columns>
	</mx:DataGrid>

相关推荐