求助!!!flex大牛!DataGridColumn里单元格加下拉框,并取值

刀刀亮 2013-06-27 03:35:51
原来的flex程序需要修改,原先是DataGrid里有两个DataGridColumn,一个是名称,一个是值。dataprovider用于填值,现在需求有变化,需要某列的值变为下拉框,进行选择。代码如下:
1.视图区域:
<mx:DataGrid id="dgProp" width="100%" height="100%" editable="true" itemEditEnd="onGridEditEnd(event);">
<mx:columns>
<mx:DataGridColumn sortable="false" headerText="名称" width="80" dataField="name" editable="false"/>
<mx:DataGridColumn sortable="false" headerText="值" dataField="value" wordWrap="true"/>

</mx:columns>
<mx:dataProvider>
{properties}
</mx:dataProvider>
</mx:DataGrid>
2.代码区域:
private function setProperties(icon:FlowIcon): void{

properties.addItem({name: "名称", value: icon.name});
properties.addItem({name: "标签", value: icon.label});
properties.addItem({name: "业务名称", value: icon.memo});

properties.addItem({name: "命令字", value:icon.commandkey});
properties.addItem({name:"详情url",value:icon.urldetail});
properties.addItem({name:"编辑url",value:icon.editurl});}

需要实现的效果:

...全文
633 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
GUNNER_10 2013-12-15
  • 打赏
  • 举报
回复
xiaolang_1 ,我也有遇到相同的问题。我是想每一列的下拉框都互不相关,请指教啊。
刀刀亮 2013-07-08
  • 打赏
  • 举报
回复
[quote=引用 4 楼 kgonihao 的回复:] 大概给你写了一个,代码没太优化,写法很活,很多种,种写法只是比较好理解点. 非常感谢你的例子,但是我还是有个问题,为什么我点击值一列的时候,会出现[object Object],而且下拉框也是出现一秒钟的下拉,然后也是变成[object Object]的输入框呢?
刀刀亮 2013-07-05
  • 打赏
  • 举报
回复
引用 4 楼 kgonihao 的回复:
大概给你写了一个,代码没太优化,写法很活,很多种,种写法只是比较好理解点.
<?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/mx"
			   width="600"
			   height="650">

	<fx:Declarations>
		<fx:XMLList id="employees">
			<employee>
				<name>Christina Coenraets</name>
				<phone>555-219-2270</phone>
				<email>ccoenraets@fictitious.com</email>
				<test>Name098899</test>
			</employee>
			<employee>
				<name>Joanne Wall</name>
				<phone>555-219-2012</phone>
				<email>jwall@fictitious.com</email>
				<test>andy</test>
			</employee>
			<employee>
				<name>Maurice Smith</name>
				<phone>555-219-2012</phone>
				<email>maurice@fictitious.com</email>
				<test>得得得</test>
			</employee>
			<employee>
				<name>test</name>
				<phone>555-219-2000</phone>
				<email>mjones@fictitious.com</email>
				<test>ererer</test>
			</employee>
		</fx:XMLList>

	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			[Bindable]
			public var elecItems:ArrayCollection=new ArrayCollection([{label: "Samsung 25in TV", data: 299}, {label: "Panasonic Plasma", data: 999}, {label: "Sony LCD", data: 899}]);
			[Bindable]
			public var str:String="";
			[Bindable]
			public var combStr:String="";
		]]>
	</fx:Script>

	<s:layout>
		<s:HorizontalLayout horizontalAlign="center"/>
	</s:layout>

	<s:Panel title="DataGrid Control"
			 color="0x000000"
			 borderAlpha="0.15"
			 width="600">

		<s:layout>
			<s:VerticalLayout paddingLeft="10"
							  paddingRight="10"
							  paddingTop="10"
							  paddingBottom="10"/>
		</s:layout>

		<s:Label width="100%"
				 color="0x323232"
				 text="Select a row in the DataGrid control."/>

		<mx:DataGrid id="dg"
					 color="0x323232"
					 width="100%"
					 dataProvider="{employees}">
			<mx:columns>
				<mx:DataGridColumn dataField="name"
								   headerText="Name">
					<mx:itemRenderer>
						<fx:Component>
							<mx:Label>
								<fx:Script>
									<![CDATA[
										import mx.managers.PopUpManager;

										override public function set data(value:Object):void
										{
											super.data=value;
											this.text=data.name;
											outerDocument.str=data.name;
										}
									]]>
								</fx:Script>
							</mx:Label>
						</fx:Component>
					</mx:itemRenderer>
				</mx:DataGridColumn>
				<mx:DataGridColumn dataField="phone"
								   headerText="Phone"/>
				<mx:DataGridColumn dataField="email"
								   id="em"
								   headerText="Email"/>
				<mx:DataGridColumn dataField="test"
								   headerText="Value">
					<mx:itemRenderer>
						<fx:Component>
							<mx:HBox width="100%"
									 horizontalScrollPolicy="off"
									 verticalScrollPolicy="off"
									 paddingLeft="5"
									 paddingRight="5">
								<fx:Script>
									<![CDATA[
										import mx.controls.Alert;
										import mx.events.ListEvent;

										override public function set data(obj:Object):void
										{
											super.data=obj;
											txt_va.text=data.test;
											if(outerDocument.str=="test")
											{
												txt_va.includeInLayout=false;
												txt_va.visible=false;
												
												comb.includeInLayout=true;
												comb.visible=true;
											}else
											{
												txt_va.includeInLayout=true;
												txt_va.visible=true;
												
												comb.includeInLayout=false;
												comb.visible=false;
											}
										}

										protected function combobox1_changeHandler(event:ListEvent):void
										{
											outerDocument.combStr=comb.selectedItem.label;//
											outerDocument.combStr=comb.selectedItem.data;
											Alert.show(outerDocument.combStr);
										}
									]]>
								</fx:Script>
								<s:Label id="txt_va"/>
								<mx:ComboBox labelField="label"
											 id="comb"
											 change="combobox1_changeHandler(event)"
											 dataProvider="{outerDocument.elecItems}"/>

							</mx:HBox>

						</fx:Component>
					</mx:itemRenderer>
				</mx:DataGridColumn>
			</mx:columns>
		</mx:DataGrid>


	</s:Panel>

</s:Application>
能不能是动态生成的啊,最好是直接在as里写。 因为我需要根据条件显示不同,最好能在我原来的代码基础上加,。 我是新手,刚开始用flex,基本上啥也不会,特别纠结。。。。。。 如果能帮我解决这个大难题,另有50分赠送,谢谢!!!
kgonihao 2013-07-03
  • 打赏
  • 举报
回复
大概给你写了一个,代码没太优化,写法很活,很多种,种写法只是比较好理解点.
<?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/mx"
			   width="600"
			   height="650">

	<fx:Declarations>
		<fx:XMLList id="employees">
			<employee>
				<name>Christina Coenraets</name>
				<phone>555-219-2270</phone>
				<email>ccoenraets@fictitious.com</email>
				<test>Name098899</test>
			</employee>
			<employee>
				<name>Joanne Wall</name>
				<phone>555-219-2012</phone>
				<email>jwall@fictitious.com</email>
				<test>andy</test>
			</employee>
			<employee>
				<name>Maurice Smith</name>
				<phone>555-219-2012</phone>
				<email>maurice@fictitious.com</email>
				<test>得得得</test>
			</employee>
			<employee>
				<name>test</name>
				<phone>555-219-2000</phone>
				<email>mjones@fictitious.com</email>
				<test>ererer</test>
			</employee>
		</fx:XMLList>

	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			[Bindable]
			public var elecItems:ArrayCollection=new ArrayCollection([{label: "Samsung 25in TV", data: 299}, {label: "Panasonic Plasma", data: 999}, {label: "Sony LCD", data: 899}]);
			[Bindable]
			public var str:String="";
			[Bindable]
			public var combStr:String="";
		]]>
	</fx:Script>

	<s:layout>
		<s:HorizontalLayout horizontalAlign="center"/>
	</s:layout>

	<s:Panel title="DataGrid Control"
			 color="0x000000"
			 borderAlpha="0.15"
			 width="600">

		<s:layout>
			<s:VerticalLayout paddingLeft="10"
							  paddingRight="10"
							  paddingTop="10"
							  paddingBottom="10"/>
		</s:layout>

		<s:Label width="100%"
				 color="0x323232"
				 text="Select a row in the DataGrid control."/>

		<mx:DataGrid id="dg"
					 color="0x323232"
					 width="100%"
					 dataProvider="{employees}">
			<mx:columns>
				<mx:DataGridColumn dataField="name"
								   headerText="Name">
					<mx:itemRenderer>
						<fx:Component>
							<mx:Label>
								<fx:Script>
									<![CDATA[
										import mx.managers.PopUpManager;

										override public function set data(value:Object):void
										{
											super.data=value;
											this.text=data.name;
											outerDocument.str=data.name;
										}
									]]>
								</fx:Script>
							</mx:Label>
						</fx:Component>
					</mx:itemRenderer>
				</mx:DataGridColumn>
				<mx:DataGridColumn dataField="phone"
								   headerText="Phone"/>
				<mx:DataGridColumn dataField="email"
								   id="em"
								   headerText="Email"/>
				<mx:DataGridColumn dataField="test"
								   headerText="Value">
					<mx:itemRenderer>
						<fx:Component>
							<mx:HBox width="100%"
									 horizontalScrollPolicy="off"
									 verticalScrollPolicy="off"
									 paddingLeft="5"
									 paddingRight="5">
								<fx:Script>
									<![CDATA[
										import mx.controls.Alert;
										import mx.events.ListEvent;

										override public function set data(obj:Object):void
										{
											super.data=obj;
											txt_va.text=data.test;
											if(outerDocument.str=="test")
											{
												txt_va.includeInLayout=false;
												txt_va.visible=false;
												
												comb.includeInLayout=true;
												comb.visible=true;
											}else
											{
												txt_va.includeInLayout=true;
												txt_va.visible=true;
												
												comb.includeInLayout=false;
												comb.visible=false;
											}
										}

										protected function combobox1_changeHandler(event:ListEvent):void
										{
											outerDocument.combStr=comb.selectedItem.label;//
											outerDocument.combStr=comb.selectedItem.data;
											Alert.show(outerDocument.combStr);
										}
									]]>
								</fx:Script>
								<s:Label id="txt_va"/>
								<mx:ComboBox labelField="label"
											 id="comb"
											 change="combobox1_changeHandler(event)"
											 dataProvider="{outerDocument.elecItems}"/>

							</mx:HBox>

						</fx:Component>
					</mx:itemRenderer>
				</mx:DataGridColumn>
			</mx:columns>
		</mx:DataGrid>


	</s:Panel>

</s:Application>
刀刀亮 2013-07-02
  • 打赏
  • 举报
回复
刀刀亮 2013-06-27
  • 打赏
  • 举报
回复
自己顶一下

4,327

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧