当前位置: 代码迷 >> Web前端 >> DataGrid渲染器范例(父类data方法应用版)
  详细解决方案

DataGrid渲染器范例(父类data方法应用版)

热度:334   发布时间:2012-10-24 14:15:58.0
DataGrid渲染器实例(父类data方法应用版)
1、 test.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/halo"
			   minWidth="1024" minHeight="768"
			   creationComplete="init();">
	<fx:Script>
		<![CDATA[
			
			public var testStr:String = "父程序测试属性";    //必须是public的才能被渲染器访问
			public var xmlSource:XML = new XML(<root></root>);
			
			public function init():void{
				for(var i:Number = 0; i < 30; i++){
					xmlSource.appendChild(
									<word>
										<myName>{"中关村" + i}</myName>
									</word>);  
				}
				dataGridID.dataProvider = xmlSource.word;  
			}
			
			public function parentsMed01(str:String, str2:String):void{    //必须是public的才能被渲染器访问
//			    trace(str);
//				trace(str2);
			}
			
			public function parentsMed02():void{
				dataGridID.dataProvider = null;
			}
			
		]]>
	</fx:Script>
	
	<mx:Label id="parentsLabelID" x="400" y="10" color="#FF0000" text="我是父程序的Label组件呵呵"
			  click="parentsMed02();"/>
	
	<mx:DataGrid id="dataGridID" x="300" y="50" width="600" height="180" backgroundColor="#000000" color="#000000">
		<mx:columns>
			<mx:DataGridColumn dataField="myName" headerText="姓名"/>
			<mx:DataGridColumn dataField="" itemRenderer="inButton" headerText="专辑名" />
		</mx:columns>
	</mx:DataGrid>
	
</s:Application>






2、 inButton.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" maxWidth="80" height="30" backgroundColor="red">
	
	<mx:Script>
		<![CDATA[
			[Bindable]
			private var musicMessage:String;
			
			/*1、其执行次数或顺序(传过来的数据)是根据当前的具体可视化的组件的数量来定(在浏览器或air上),
			     而且是根据用户改变可显示区域动态即时改变的;且每次执行时数据只是一单位部分,即对应一行。
			     (一句话总结:只动态加载当前可视化部分的全部组件)
			  2、已每行为单位进行对应次数的调用此方法;即数据的传递都是以对应组件的每行为单位。
			  3、加载的测试结果:
			     (1)、初始化时:全部的数据已经都可以看到的:规律是: 1 ALL(当前可视化的数据行数)
                            ===中关村0
							===中关村0
							===中关村1
							===中关村2
							===中关村3
							===中关村4
			     (2)、初始化时:当前可视化的数据不是全部的数据:规律是: 1 ALL(当前可视化的数据行数) ALL(当前可视化的数据行数)
							===中关村0
							===中关村0
							===中关村1
							===中关村2
							===中关村3
							===中关村4
							===中关村0
							===中关村1
							===中关村2
							===中关村3
							===中关村4
			
			*/
			override public function set data(value:Object):void{    //实例化父DataGrid时(此事件)自动执行此方法
				var str:String="";
				super.data = value;    //value就是渲染器所在父组件的数据源的内容
				musicMessage = value["myName"];
				trace("===" + musicMessage);
			}
			
			private function aa(str:String):void{
				this.parentDocument.parentsLabelID.text = "AAAAA,被渲染器改变了啊---" + str;    //渲染器调用父组件
//				trace(this.parentDocument.testStr);    //渲染器调用父属性
				this.parentDocument.testStr = "我是渲染器传过来的";    //渲染器改变父类属性值
			    this.parentDocument.parentsMed01(str, this.parentDocument.testStr);    //渲染器调用父函数
			}
			
		]]>
	</mx:Script>
	
	<mx:Button id="butID" label="{musicMessage}" click="aa(this.data.myName);"/>
	<mx:Label id="labID" x="50" fontSize="12" text="世界"/>
	<mx:Label id="lab2ID" x="80" text="哈哈哈"/>
</mx:Canvas>






  相关解决方案