熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

Flex 基於數據源的Menu Tree

2013-11-15 11:38:07  來源: JSP教程 

  實現功能

  由外部參數flashvars指定數據源的文件位置或render鏈接

  在源數據上加href和target屬性來控制打開窗口

  可自定義父節點和子節點圖標不設置采用系統默認

  直接上源碼

   <?xml version= encoding=utf?>
<mx:Application xmlns:mx= 
     fontFamily=simsun fontSize= 
     layout=absolute creationComplete=menusend(); width= height= initialize=init()>
<mx:Script>
    <![CDATA[
        import ntrolsAlert;
        import mxeventsListEvent;
         import llectionsArrayCollection;
         import mxrpceventsResultEvent;

         [Bindable]
         private var strUrl:String = TreeMenusxml;
         
         [Bindable]
         private var menus:XML;
         
         [Bindable]
         [Embed(opengif)]
         public var openicon:Class;
         
          [Bindable]
          [Embed(closegif)]
         public var closeicon:Class;
         
          [Bindable]
          [Embed(leafgif)]
         public var leaficon:Class;
         
         private function init():void
         {
              thisstrUrl = thisparametersurl;
         }
         
         private function LoadMenu(event:ResultEvent):void
         {
             menus = XML(eventresult);
             var results:XMLList = menusnode;
             treedataProvider = results;
         }
         //菜單圖標設置
         private function treeIcon(item:Object):Class
         {
             
              var node:XML = XML(item);
              trace(icon: + node@icon);
              var str : String = node@icon;
              //已經設置圖標
              if(nodehasOwnProperty(@icon))
              {
                  if(node@icon == openicon)
                  {
                        return openicon;
                  }
                  if(node@icon == closeicon)
                  {
                        return closeicon;
                  }
                  if(node@icon == leaficon)
                  {
                        return leaficon;
                  }
              }
              else
              {
                //如果沒定義icon就直接用默認的                       
                  if(!treedataDescriptorisBranch(item))
                  {
                      return treegetStyle(defaultLeafIcon);
                }
                if(treeisItemOpen(item))
                {
                      return treegetStyle(folderOpenIcon);
                }
                else
                {
                    return treegetStyle(folderClosedIcon);
                }
              }
              return null;
        }
        
         /** *//**
         * 菜單樹單項點擊事件
         * */
         private function itemClickHandler(evt:ListEvent):void
           {
                var item:Object = Tree(evtcurrentTarget)selectedItem;
                if (treedataDescriptorisBranch(item)) 
                {
                   //treeexpandItem(item !groupTreeisItemOpen(item) true);
                }
                else
                {
                    //得到節點對象
                    var node:XML = XML(item);
                    //如果有屬性href
                    if(nodehasOwnProperty(@href) && nodehasOwnProperty(@target))
                    {
                        openURL(node@hrefnode@target);
                    }
                    if(nodehasOwnProperty(@href) && (nodehasOwnProperty(@target) == false))
                    {
                        //沒有指定target默認在新窗口中打開
                        openURL(node@href_blank);
                    }
                }
          }
             
         //頁面跳轉的方法 
          private function openURL(url:String target:String):void
          {
             var request:URLRequest = new URLRequest(url); 
             navigateToURL(requesttarget);
          }
    ]]>
</mx:Script>
    <mx:HTTPService url={strUrl} id=menu useProxy=false 
         showBusyCursor=true result=LoadMenu(event) resultFormat=xml/>
    <mx:Tree iconFunction=treeIcon id=tree width=% height=% labelField=@label  itemClick=itemClickHandler(event)/>
</mx:Application>

  調用的時候在flashvars裡面加上url=xxx

   <object classid=clsid:DCDBEAEDcfB
            id=tree width= height=
            codebase=>
            <param name=movie value=${ctx}/js/as/menuswf />
            <param name=quality value=high />
            <param name=bgcolor value=#ca />
            <param name=allowScriptAccess value=sameDomain />
            <! 指定菜單的數據源 >
            <param name=flashvars value=url=${ctx}/user/user!renderMenudo?id=${userusid} />
            <embed src=treeswf quality=high bgcolor=#ca
                width= height= name=tree align=middle
                play=true
                loop=false
                quality=high
                allowScriptAccess=sameDomain
                type=application/xshockwaveflash
                pluginspage=>
            </embed>
    </object>

  其中url可以指定xml文件的位置或者render的鏈接

  示例文件xml

   <?xml version= encoding=utf?>
<menus>
    <node label=系統管理 icon=openicon>
        <node label=用戶管理 icon=closeicon
             target=mainFrame />
        <node label=權限管理 
            target=mainFrame />
        <node label=角色管理 
            target=mainFrame />
        <node label=域管理 
            target=mainFrame />
        <node label=測試>
            <node label=sub folder  target=mainFrame />
        </node>
    </node>
    <node label=客服>
        <node label=終端信息查詢  target=mainFrame />
        <node label=客服問題解答記錄  target=mainFrame />
    </node>
</menus>

  

  源碼下載點擊


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19340.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.