flex TreeGrid使用

 flex端

一,首先引入 trees  xmlns:trees="http://code.google.com/p/flexlib/"

二 定义变量  private var reslutList:ArrayList=new ArrayList();
			
							private var timer:Timer = new Timer(300,1);
							[Bindable]
							private var data_list:Array = null;
							
三、定义方法:
   //定时器
   protected function onTimer(event:TimerEvent):void{
				openItem();
			}
	//展开树
			protected function openItem():void
			{
				for(var i:int=0; i<data_list.length; i++)
				{
					if(!data_list[i].leaf)//如果还有下一级
					{
						detail_tree.openItemAt(i);
					}
				}
			}
			
			/**
			 * 取出所有节点的数据
			 * */
			private function getListByGrid(list:Array):void{
				
				for(var i:int=0;i<list.length;i++){
					var o:Object=list[i];
					if(o.hasOwnProperty("leaf")){
						reslutList.addItem(o);
					}else{
						getListByGrid(o.children);
					}
				}
			}
			
			//加载数据
			protected function load_grid(year:String):void
			{
				// TODO Auto-generated method stub
				var param:URLVariables = new URLVariables();
				param.orgCd = HttpUtil.loginOrgCd;
				param.businessYear =year;// this.year;
				HttpUtil.doPost("bfProjectBudgetAction!getBfProjectBudget.do", param, function(message:Object):void{
					if(message.data.list!=null){
						detail_tree.dataProvider = message.data.tree;
						data_list=message.data.list;
						timer.start();
					}
				});
			}
			
			//保存方法
			protected function saveBtn_clickHandler(event:MouseEvent):void
			{
				reslutList=new ArrayList();
				var list:ArrayCollection=detail_tree.dataProvider as ArrayCollection;
				getListByGrid(list.toArray());
				var param:URLVariables = new URLVariables();
				var json:String=JSON.encode(reslutList.toArray());
				param.json=json;
				HttpUtil.doPost("bfProjectBudgetAction!updateBfProjectBudgetSubsidyDemo.do",param,function(obj:Object):void{
					if(obj.data.error){
						Message.showError("保持失败!");
					}else{
						Message.showSuccess("保存成功!");
					}
				});
			}
四、定义表格:
<trees:TreeGrid
				headerBackgroundSkin="skin.grid.MxGridHeaderSkin"
				borderColor ="#C8CCCE"
				id="detail_tree" showRoot="false" editable="true"
				width="100%" height="100%" sortableColumns="false" 
				disclosureClosedIcon="@Embed(source='/images/treegrid/arrow_down.png')"
				disclosureOpenIcon="@Embed(source='/images/treegrid/arrow_down.png')"
				folderOpenIcon="@Embed(source='/images/treegrid/arrow_down.png')"
				folderClosedIcon="@Embed(source='/images/treegrid/arrow_down.png')"
				defaultLeafIcon="@Embed(source='/images/treegrid/arrow_down.png')" 
				>
				<trees:columns>
					<trees:TreeGridColumn id="projectTypeName" headerText="项目类型" dataField="projectTypeName" editable="false" textAlign="left"/>
					<mx:DataGridColumn id="gcl" headerText="计划工程量" dataField="projectQty"  textAlign="center" editable="false" />
					<mx:DataGridColumn id="unitName" headerText="单位" dataField="unitName" textAlign="center" editable="false"/>
					<mx:DataGridColumn  headerText="* 国家补贴(元)" dataField="countrySubsidy"  textAlign="center" editable="true" >
						<mx:itemEditor>
							<fx:Component>
								<mx:TextInput  restrict="0-9."  visible="{data.leaf}" editable="{data.leaf}"  width="100%" height="100%"/>
							</fx:Component>
						</mx:itemEditor> 
					</mx:DataGridColumn>
					<mx:DataGridColumn  headerText="budgetId" dataField="budgetId" visible="false"/>
				</trees:columns>
			</trees:TreeGrid>
			


java端

	一、取数据方法
			
	  newList.add(0, new SMap("projectTypeCd", "0", "projectTypeName", "项目类型", "projectParentId", null));
		Map tree = TreeUtil.getTree(newList, "0", "projectTypeCd", "projectParentId");
		newList.remove(0);
		Map result = new HashMap();
		result.put("tree", tree);
		result.put("list", newList);
		this.output(result)
		
		****取数据时一定要排序,因为这个问题今天查了很久才查出来,这种问题真的很要命。。
		
		二 保存数据
		
		  Map outPut=new HashMap();
    	String json = getReq().getParameter("json");
    	List list = (List) JSON.parseArray(json, Map.class);
    	try{
    		bfProjectBudgetService.updateBfProjectBudgetFlagDemo(shType,list);
    		outPut.put("error", false);
    	}catch(Exception e){
    		outPut.put("error", true);
    		outPut.put("errorString", "保存失败");
    	}
    	this.output(outPut);
		


TreeUtil需要引进pipi-framework.jar

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值