分享好友 编程语言首页 频道列表

Flex基于数据源的MenuTree实现代码

flex  2015-06-26 11:570
实现功能:
1.由外部参数flashvars指定数据源的文件位置或render链接.
2.在源数据上加href和target属性来控制打开窗口.
3.可自定义父节点和子节点图标,不设置采用系统默认.
直接上源码:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/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.com/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="allowscr-iptaccess" 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"
allowscr-iptaccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/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='http://www.lexue001.com/main/user/user-list.jsp' target='mainFrame' />
<node label='权限管理' href='http://www.lexue001.com/main/user/action-list.jsp'
target='mainFrame' />
<node label='角色管理' href='http://www.lexue001.com/main/user/role-list.jsp'
target='mainFrame' />
<node label='域管理' href='http://www.lexue001.com/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>

Flex基于数据源的MenuTree实现代码

查看更多关于【flex】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
Delphi动态配置ODBC数据源--SQL Server版本
(摘自)http://jxlearnew.blog.163.com/blog/static/549786592007102451431413/这里介绍一种用Delphi来实现动态注册的方法,希望对各位有所帮助.这里我们直接使用ODBCCP32.DLL中提供的SQLConfigDataSource函数来实现,该函数在在Delphi中可声明如下://配置ODBC数

0评论2023-02-09498

ruby gem源更换国内源gems.ruby-china.org数据源
gem sources -lgem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/更新缓存gem sources -u 

0评论2023-02-08426

MySQL数据源表结构图示
今天我把ITIS系统数据源的表结构公布给大家,在今后的开发过程中,将一直会用到这张表。当然,随着开发的推进,有可能还会修改此表,到时候会另外说明。

0评论2015-11-1842

PHP实现域名whois查询的代码(数据源万网、新网)
对于whois查询,数据来自万网、新网,数据也比较权威,需要的朋友可以参考下。

0评论2015-11-1775

C#实现ComboBox控件显示出多个数据源属性的方法
这篇文章主要介绍了C#实现ComboBox控件显示出多个数据源属性的方法,实例分析了ComboBox控件的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下

0评论2015-09-2289

php连接odbc数据源并保存与查询数据的方法
这篇文章主要介绍了php连接odbc数据源并保存与查询数据的方法,涉及odbc数据源的操作技巧,非常具有实用价值,需要的朋友可以参考下

0评论2015-08-10114

C#连接ODBC数据源的方法
这篇文章主要介绍了C#连接ODBC数据源的方法,实例分析了C#连接ODBC操作数据库的技巧,非常具有实用价值,需要的朋友可以参考下

0评论2015-07-14115

Tomcat数据源配置方法_JBuilder中
今天帮一同事配置一个数据源,采用tomcat5.5.9,本来是个很简单的事,以前也配过,但由于很长时间没用过容器提供的数据源了(IOC用惯了),也只记的个大概了,所以刚开始一配就出错了,google了一下,有很多资料,照着试试却都不好使(到不是别人说的不对,只是大家用的版本不同)。

0评论2015-06-2385

更多推荐