最近在看Flex,用RemoteObject方法(Blazeds)做了个动态加载树的小例子,不是很好,以后再慢慢改进吧.
mxml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script >
<![CDATA[
import mx.events.ListEvent;
import mx.events.TreeEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
import mx.collections.XMLListCollection;
private var _node:XML;
[Bindable]
private var xmlTree:XML = <node nodename="root" id="0" is_parent="1" parentnode="" action="">
<nodetemp nodename="" id="" is_parent="" parentnode="" action=""></nodetemp>
</node>;
private function addNewNode(treenode:XML,resultList:ArrayCollection):void{
if(null==resultList){
return ;
}
for(var i:Number=0;i<resultList.length;i++){
var newNode:XML = <node/>;
newNode.@id=resultList[i]["node"];
newNode.@is_parent=resultList[i]["is_parent"];
newNode.@nodename=resultList[i]["nodename"];
newNode.@parentnode=resultList[i]["parentnode"];
newNode.@action=resultList[i]["action"];
right_tree.dataDescriptor.addChildAt(treenode, newNode, i, treenode);
//如果有子节点就创建临时节点,让这个节点有itemOpen的方法
if("1"==resultList[i]["is_parent"]){
var nodetemp:XML = <nodetemp/>;
right_tree.dataDescriptor.addChildAt(newNode, nodetemp, 0, newNode);
}
}
}
private function getRightByParntResult(event:ResultEvent):void{
var resultList:ArrayCollection =event.result as ArrayCollection;
addNewNode(_node,resultList);
}
private function tree_itemOpen(evt:TreeEvent):void {
var t:Tree = evt.currentTarget as Tree;
_node= evt.itemRenderer.data as XML;
var hasload:Boolean = false;
var xmllist:XMLList = _node.elements("nodetemp");
//删除拥有子节点的临时节点
if(null != xmllist && xmllist.length() >0 ){
for(var i:Number=0;i<xmllist.length();i++){
var temp:XML = xmllist[i] as XML
right_tree.dataDescriptor.removeChildAt(_node,temp,i,_node);
}
}
xmllist =_node.elements("node");
//如果这个节点已经取过子节点就返回,不需要再取
if(null!=xmllist&&xmllist.length()>0){
return;
}
rightHandler.endpoint="messagebroker/amf";
var nodeid:String=_node.@id ;
rightHandler.getRightByParent(nodeid);
}
]]>
</mx:Script>
<mx:RemoteObject id="rightHandler" destination="rightHandler" >
<mx:method name="getRightByParent" result="getRightByParntResult(event)" />
</mx:RemoteObject>
<mx:Tree id="right_tree"
dataProvider="{xmlTree}"
itemOpen="tree_itemOpen(event)"
labelField="@nodename"
bottom="0" top="25" right="0" left="0">
</mx:Tree>
</mx:Application>
Java代码
package com.cpk.service;
import java.util.List;
import java.util.Map;
import com.cpk.dao.RightDao;
public class RightHandler {
public List<Map<String,String>> getRightByParent(String parentID){
RightDao dao=new RightDao();
return dao.query(parentID);
}
}
package com.cpk.dao;
import java.util.List;
import java.util.Map;
import com.caipk.newjdbc.sql.Finder;
import com.caipk.newjdbc.template.Jdbc;
public class RightDao extends Jdbc {
public List<Map<String,String>> query(String parentid){
return this.query(
Finder.create("select node,parentnode,nodename,action,title,closeimg,openimg,")
.append(" decode( (select node from right t where node in(select distinct parentnode from right where status='0') and t.node=right.node and parentnode=?),null,'0','1') as is_parent ")
.append(" from right")
.append(" where parentnode=?")
.setParam(parentid)
.setParam(parentid)
);
}
}
remoting-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService">
<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
<!--
<destination id="GenericDestination">
<properties>
<source>*</source>
</properties>
</destination>
-->
<destination id="EmployeeHandler">
<properties>
<source>com.cpk.service.EmployeeHandler</source>
</properties>
</destination>
<destination id="rightHandler">
<properties>
<source>com.cpk.service.RightHandler</source>
</properties>
</destination>
</service>
分享到:
- 2009-07-28 16:02
- 浏览 1844
- 评论(3)
- 论坛回复 / 浏览 (3 / 6775)
- 查看更多
相关推荐
flexBulider页面加载动态图片的显示
flex动态加载css实例flex动态加载css实例flex动态加载css实例
3.RadioTreeNode,4.RadioTreeRenderer,1为支持联表查询的单选树(已封装),第一张表查询的为非叶子节点,第二张表查询的记录为叶子节点,比如要构造人员树,部门为非叶子节点,人员为叶子节点,分布在两张表中。...
FLEX 动态树 动态图表 FLEX 动态树 动态图表
flex 动态加载css文件方法总结,增加flex的界面美化效果。简单易懂,易操作。
NULL 博文链接:https://demojava.iteye.com/blog/1337123
flex 动态生成树
y="20"> x="20" dataProvider="{loadingxml}" y="10" height="400" width="394" labelField="@label" itemClick="tree_itemClick(event);... itemOpening="tree_itemOpening(event);...
很详细的实现了flex游戏的预加载,可以使用图片,也可以重绘技术,任你选择
Flex中加载SWF方法,介绍了flex 对 swf 加载和处理
flex自定义的预加载进度条动画的一个demo,非常使用。
FLEX动态加载gif图形,需要的GifPlayer.swc,导入包,new gifplayer(),来使用
flex arcgis 加载天地图2.0地图源码
Flex自定义加载条的一个小示例。里面有readMe文本
flex4 选择树组件。可以直接使用组件包。在Test.mxml里面有使用的测试。
NULL 博文链接:https://taomujian.iteye.com/blog/315266
NULL 博文链接:https://emavaj.iteye.com/blog/676072
Flex ComBox 下拉树功能例子 以及相关代码
利用flex开发web时,需要加载html,附件中时采用flex3做的示例。
Flex实时加载Skin,flex 方法,技巧