欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Flex动态生成DataGrid及加载图片

程序员文章站 2022-05-05 19:54:32
...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initHandler()">
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Image;
			import mx.controls.Alert;
			import mx.controls.dataGridClasses.DataGridColumn;
			[Bindable]  
			public var grid:Array = [ {dept:"人力", name:"张三", sex:0, age:25, mobile:"123456"},
				{dept:"人力", name:"李四", sex:1, age:20, mobile:"123456"},
				{dept:"研发", name:"王五", sex:1, age:21, mobile:"123456"},
				{dept:"研发", name:"赵六", sex:0, age:22, mobile:"123456"},
				{dept:"研发", name:"钱七", sex:1, age:23, mobile:"123456"}];
			public var gridHeader:Array = [
				{hName:"部门",hCode:"dept"},
				{hName:"姓名",hCode:"name"},
				{hName:"性别",hCode:"sex"},
				{hName:"年龄",hCode:"age"},
				{hName:"手机",hCode:"mobile"}];
			public var gridArray:ArrayCollection;
			public var columns:Array;
			public var column:DataGridColumn;
			var read:ClassFactory = new ClassFactory(reader);
			
			public function initHandler():void{
				gridArray = new ArrayCollection(grid);
				gridArray.filterFunction;
				dataGrid.x = 20;
				dataGrid.y = 20;
				dataGrid.setStyle("textAlign","center");
				columns = new Array();
				for each ( var obj:Object in gridHeader ){
					column = new DataGridColumn();
					if(obj.hCode == "sex"){
						column.itemRenderer = read;
					}
					column.headerText = obj.hName;
					column.dataField = obj.hCode;
					columns.push(column);
				}
				dataGrid.columns = columns;
				dataGrid.dataProvider = gridArray;
				addChild(dataGrid);
			}
			
		]]>
	</mx:Script>
	<mx:DataGrid id="dataGrid" height="95%" width="95%"/>
</mx:Application>

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Image xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="center">
	<mx:Script>
	<![CDATA[
		import mx.controls.Image;
	
	        import mx.collections.ArrayCollection;
	        import mx.controls.Alert;
	        [Bindable]
	        public var dataProvider:ArrayCollection;
			
			private var _data:Object;
			
			override public function set data(value:Object):void{
				if(value.sex==0){
					this.source = "../image/woman.png";
				}
				if(value.sex==1){
					this.source = "../image/man.png";
				}
			}
			
			override public function get data():Object
			{
				return _data;
			}
   	]]>			
</mx:Script>			
</mx:Image>

 

相关标签: flex