Flex 基于数据源的Menu Tree实现代码
网络编程 2021-07-05 11:32www.168986.cn编程入门
由外部参数flashvars指定数据源的文件位置或render链接,在源数据上加href和target属性来控制打开窗口,可自定义父节点和子节点图标,不设置采用系统默认,感兴趣的你可以了解下啊,或许对你有所帮助
实现功能:
1.由外部参数flashvars指定数据源的文件位置或render链接.
2.在源数据上加href和target属性来控制打开窗口.
3.可自定义父节点和子节点图标,不设置采用系统默认.
直接上源码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://.adobe./2006/mxml"
fontFamily="simsun" fontSize="12"
layout="absolute" creationComplete="menu.send();" width="242" height="442" initialize="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var strUrl:String = "TreeMenus.xml";
[Bindable]
private var menus:XML;
[Bindable]
[Embed("open.gif")]
public var openicon:Class;
[Bindable]
[Embed("close.gif")]
public var closeicon:Class;
[Bindable]
[Embed("leaf.gif")]
public var leaficon:Class;
private function init():void
{
this.strUrl = this.parameters.url;
}
private function LoadMenu(event:ResultEvent):void
{
menus = XML(event.result);
var results:XMLList = menus.node;
tree1.dataProvider = results;
}
//菜单图标设置
private function treeIcon(item:Object):Class
{
var node:XML = XML(item);
trace('icon:' + node.@icon);
var str : String = node.@icon;
//已经设置图标
if(node.hasOwnProperty("@icon"))
{
if(node.@icon == 'openicon')
{
return openicon;
}
if(node.@icon == 'closeicon')
{
return closeicon;
}
if(node.@icon == 'leaficon')
{
return leaficon;
}
}
else
{
//如果没定义icon就直接用默认的
if(!tree1.dataDescriptor.isBranch(item))
{
return tree1.getStyle("defaultLeafIcon");
}
if(tree1.isItemOpen(item))
{
return tree1.getStyle("folderOpenIcon");
}
else
{
return tree1.getStyle("folderClosedIcon");
}
}
return null;
}
/
菜单树单项点击事件
/
private function itemClickHandler(evt:ListEvent):void
{
var item:Object = Tree(evt.currentTarget).selectedItem;
if (tree1.dataDescriptor.isBranch(item))
{
//tree1.expandItem(item, !groupTree.isItemOpen(item), true);
}
else
{
//得到节点对象
var node:XML = XML(item);
//如果有属性href
if(node.hasOwnProperty("@href") && node.hasOwnProperty("@target"))
{
openURL(node.@href,node.@target);
}
if(node.hasOwnProperty("@href") && (node.hasOwnProperty("@target") == false))
{
//没有指定target默认在新窗口中打开
openURL(node.@href,"_blank");
}
}
}
//页面跳转的方法
private function openURL(url:String ,target:String):void
{
var request:URLRequest = new URLRequest(url);
navigateToURL(request,target);
}
]]>
</mx:Script>
<mx:HTTPService url="{strUrl}" id="menu" useProxy="false"
showBusyCursor="true" result="LoadMenu(event)" resultFormat="xml"/>
<mx:Tree iconFunction="treeIcon" id="tree1" width="100%" height="100%" labelField="@label" itemClick="itemClickHandler(event)"/>
</mx:Application>
调用的时候在flashvars里面加上url=xxx
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="tree" width="242" height="442"
codebase="http://fpdownload.macromedia./get/flashplayer/current/swflash.cab">
<param name="movie" value="${ctx}/js/as/menu.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAess" value="sameDomain" />
<!-- 指定菜单的数据源 -->
<param name="flashvars" value="url=${ctx}/user/user!renderMenu.do?id=${user.usid}" />
<embed src="tree.swf" quality="high" bgcolor="#869ca7"
width="242" height="442" name="tree" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://.adobe./go/getflashplayer">
</embed>
</object>
其中url可以指定xml文件的位置或者render的链接
示例文件xml:
<?xml version='1.0' encoding='utf-8'?>
<menus>
<node label='系统管理' icon="openicon">
<node label='用户管理' icon="closeicon"
href='/main/user/user-list.jsp' target='mainFrame' />
<node label='权限管理' href='/main/user/action-list.jsp'
target='mainFrame' />
<node label='角色管理' href='/main/user/role-list.jsp'
target='mainFrame' />
<node label='域管理' href='/main/user/user-list.jsp'
target='mainFrame' />
<node label='测试'>
<node label='sub folder' href='' target='mainFrame' />
</node>
</node>
<node label='客服'>
<node label='终端信息查询' href='' target='mainFrame' />
<node label='客服问题-解答记录' href='' target='mainFrame' />
</node>
</menus>
1.由外部参数flashvars指定数据源的文件位置或render链接.
2.在源数据上加href和target属性来控制打开窗口.
3.可自定义父节点和子节点图标,不设置采用系统默认.
直接上源码:
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://.adobe./2006/mxml"
fontFamily="simsun" fontSize="12"
layout="absolute" creationComplete="menu.send();" width="242" height="442" initialize="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var strUrl:String = "TreeMenus.xml";
[Bindable]
private var menus:XML;
[Bindable]
[Embed("open.gif")]
public var openicon:Class;
[Bindable]
[Embed("close.gif")]
public var closeicon:Class;
[Bindable]
[Embed("leaf.gif")]
public var leaficon:Class;
private function init():void
{
this.strUrl = this.parameters.url;
}
private function LoadMenu(event:ResultEvent):void
{
menus = XML(event.result);
var results:XMLList = menus.node;
tree1.dataProvider = results;
}
//菜单图标设置
private function treeIcon(item:Object):Class
{
var node:XML = XML(item);
trace('icon:' + node.@icon);
var str : String = node.@icon;
//已经设置图标
if(node.hasOwnProperty("@icon"))
{
if(node.@icon == 'openicon')
{
return openicon;
}
if(node.@icon == 'closeicon')
{
return closeicon;
}
if(node.@icon == 'leaficon')
{
return leaficon;
}
}
else
{
//如果没定义icon就直接用默认的
if(!tree1.dataDescriptor.isBranch(item))
{
return tree1.getStyle("defaultLeafIcon");
}
if(tree1.isItemOpen(item))
{
return tree1.getStyle("folderOpenIcon");
}
else
{
return tree1.getStyle("folderClosedIcon");
}
}
return null;
}
/
菜单树单项点击事件
/
private function itemClickHandler(evt:ListEvent):void
{
var item:Object = Tree(evt.currentTarget).selectedItem;
if (tree1.dataDescriptor.isBranch(item))
{
//tree1.expandItem(item, !groupTree.isItemOpen(item), true);
}
else
{
//得到节点对象
var node:XML = XML(item);
//如果有属性href
if(node.hasOwnProperty("@href") && node.hasOwnProperty("@target"))
{
openURL(node.@href,node.@target);
}
if(node.hasOwnProperty("@href") && (node.hasOwnProperty("@target") == false))
{
//没有指定target默认在新窗口中打开
openURL(node.@href,"_blank");
}
}
}
//页面跳转的方法
private function openURL(url:String ,target:String):void
{
var request:URLRequest = new URLRequest(url);
navigateToURL(request,target);
}
]]>
</mx:Script>
<mx:HTTPService url="{strUrl}" id="menu" useProxy="false"
showBusyCursor="true" result="LoadMenu(event)" resultFormat="xml"/>
<mx:Tree iconFunction="treeIcon" id="tree1" width="100%" height="100%" labelField="@label" itemClick="itemClickHandler(event)"/>
</mx:Application>
调用的时候在flashvars里面加上url=xxx
代码如下:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="tree" width="242" height="442"
codebase="http://fpdownload.macromedia./get/flashplayer/current/swflash.cab">
<param name="movie" value="${ctx}/js/as/menu.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAess" value="sameDomain" />
<!-- 指定菜单的数据源 -->
<param name="flashvars" value="url=${ctx}/user/user!renderMenu.do?id=${user.usid}" />
<embed src="tree.swf" quality="high" bgcolor="#869ca7"
width="242" height="442" name="tree" align="middle"
play="true"
loop="false"
quality="high"
allowScriptAess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://.adobe./go/getflashplayer">
</embed>
</object>
其中url可以指定xml文件的位置或者render的链接
示例文件xml:
<?xml version='1.0' encoding='utf-8'?>
<menus>
<node label='系统管理' icon="openicon">
<node label='用户管理' icon="closeicon"
href='/main/user/user-list.jsp' target='mainFrame' />
<node label='权限管理' href='/main/user/action-list.jsp'
target='mainFrame' />
<node label='角色管理' href='/main/user/role-list.jsp'
target='mainFrame' />
<node label='域管理' href='/main/user/user-list.jsp'
target='mainFrame' />
<node label='测试'>
<node label='sub folder' href='' target='mainFrame' />
</node>
</node>
<node label='客服'>
<node label='终端信息查询' href='' target='mainFrame' />
<node label='客服问题-解答记录' href='' target='mainFrame' />
</node>
</menus>
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程