JQuery EasyUI 結合ztrIee的後台頁面開發執行個體

來源:互聯網
上載者:User

JQuery EasyUI 結合ztrIee的後台頁面開發執行個體

JQuery EasyUI 結合 zTree樹形結構製作web頁面.easyui用起來比較簡單,很好的封裝了jquery的部分功能,使用起來更加方便,但是從1.2.3版本以後,商業用途是需要付費的,zTree是國內的大牛們搞的一個jquery樹形tree外掛程式,感覺很好用,很強大,而且完全免費,API等做的也非常不錯.推薦

easyui 是一個基於 jQuery 的架構,整合了各種使用者介面外掛程式。
easyui 提供建立現代化的具有互動性的 javascript 應用的必要的功能。
使用 easyui,您不需要寫太多 javascript 代碼,一般情況下您只需要使用一些 html 標記來定義使用者介面。
HTML 網頁的完整架構。
easyui 節省了開發產品的時間和規模。
easyui 非常簡單,但是功能非常強大。

需要的匯入以下幾種js檔案和樣式表

easyui/themes/default/easyui.css
easyui/themes/icon.css  
jquery-1.8.3.js
easyui/jquery.easyui.min.js
ztree/jquery.ztree.all-3.5.js(該檔案包括core,exhide,exedit,excheck)
ztree/zTreeStyle.css

<script type="text/javascript">           
    // ztree菜單設定
    var zTreeObj,
    setting = {
        view: {
            selectedMulti: false
        },
        // 添加編輯設定:修改樹節點名稱/刪除樹節點
        edit: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback:{
            onClick: zTreeOnClick
        }
    };
   
    // 回呼函數:單擊事件
    function zTreeOnClick(event, treeId, treeNode, clickFlag) {
        alert(treeNode.id + ", " + treeNode.name);
        var content = '<div style="width:100%;height:100% ;overflow:hidden;">'
                            +'<iframe src="'
                            +treeNode.url
                            +'" scrolling="auto" style="width:100%;height:100%;border:0;"></iframe></div>';
        if(treeNode.url != undefined && treeNode.url != ""){
            // 當centre中是否存在名稱為treeNode.name的tabs
            if($("#tt").tabs('exists',treeNode.name)){
                $("#tt").tabs('select',treeNode.name);
            }else {
                $("#tt").tabs('add',{
                    title:treeNode.name,
                    content:content,
                    closable:true
                })
            }
        };
        event.preventDefault();
    };
   
    // 提供ztree樹形菜單資料
    zTreeNodes  = [ {"id":1, "pId":0, "name":"海賊王"},
                            {"id":11, "pId":1, "name":"娜美", "url":"http://www.bkjia.net/"},
                            {"id":12, "pId":1, "name":"羅賓", "url":"http://www.baidu.com"},
                            {"id":13, "pId":1, "name":"漢庫克", "url":"http://www.google.cn/"},
                            { "id":2,  "pId":0, "name":"父節點 2", "open":true},
                            {"id":21,"pId":2, "name":"葉子節點 2-1"},
                            {"id":22,  "pId":2, "name":"葉子節點 2-2"},
                            {"id":23,"pId":2, "name":"葉子節點 2-3"},
                            {"id":3,  "pId":0, "name":"父節點 3", "open":true},
                            {"id":31, "pId":3, "name":"葉子節點 3-1"},
                            {"id":32, "pId":3, "name":"葉子節點 3-2"},
                            {"id":33, "pId":3, "name":"葉子節點 3-3"}
                            ];
   
    // 3.產生樹形菜單
    $(document).ready(function(){
        zTreeObj = $.fn.zTree.init($("#tree"), setting, zTreeNodes);
    });
   
    // 4.物件索引標籤註冊右擊事件
    $(document).ready(function(){
        $("#tt").tabs({
            onContextMenu:function(e,title,index){
            // 阻止系統預設的右擊事件
                e.preventDefault();
                $('#mm').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            }
        });
    });
   
    // 擷取所選取的面板對象
    $(document).ready(function(){
        $("#tt").tabs({
            // 擷取所選取的面板對象
            onSelect : function(title,index ){
                // 5. menu的單擊事件綁定
                $("#mm").menu({
                    onClick:function(item){
                        alert(item.name);
                        //  當點擊關閉當前選項卡時
                        if(item.name==='current'){
                            $('#tt').tabs('close',title);
                        // 當點擊關閉其他選項卡時
                        }else if(item.name === 'others'){
                            var tabs = $('#tt').tabs('tabs');
                            $(tabs).each(function(){
                                if($(this).panel('options').title != '訊息中心' && $(this).panel('options').title != title){
                                    $('#tt').tabs('close',$(this).panel('options').title);
                                }
                            });
                        // 當點擊關閉所有選項卡時
                        }else if(item.name === 'all'){
                            var tabs = $('#tt').tabs('tabs');
                            $(tabs).each(function(){
                                        if($(this).panel('options').title != '訊息中心'){
                                    $('#tt').tabs('close',$(this).panel('options').title);
                                }
                            });
                        }
                    }
                });
            }
        })
    })   
</script>

相應的htm 部分代碼

<body class="easyui-layout">
    <div data-options="region:'north',title:'北丐:洪七公',split:true" style="height:100px;"></div>
    <div data-options="region:'south',title:'南帝:一燈大師',split:true" style="height:100px;"></div>
    <div data-options="region:'east',iconCls:'icon-reload',title:'東邪:黃藥師',split:true" style="width:100px;"></div>
    <div data-options="region:'west',title:'西毒:歐陽鋒',split:true" style="width:250px;">
        <div id="aa"  data-options="fit:'true'" class="easyui-accordion">
            <div title="趙敏" data-options="iconCls:'icon-save'" >
                <h3 style="color:#0099FF;">Accordion for jQuery</h3>
                <p>Accordion is a part of easyui framework for jQuery. It lets you define your accordion component on web page more easily.</p>
            </div>
            <div title="大玉兒" data-options="iconCls:'icon-reload',selected:true" >
                // ztree屬性結構
                <ul id="tree" class="ztree" style="width:230px; overflow:auto;"></ul>
            </div>
            <div title="婉容兒" >
                who?
            </div>
        </div>
    </div>
    <div data-options="region:'center',title:'中神通:周伯通'">
        // tabs 面板
        <div id="tt" class="easyui-tabs" data-options="fit:true">
            <div title="小龍女"data-options="closable:true" ></div>
            <div title="沐劍屏" data-options="closable:true" ></div>
            <div title="阿珂" data-options="iconCls:'icon-reload',closable:true"></div>
        </div>
    </div>
   
    // menu功能表列
    <div id="mm" class="easyui-menu" style="width:120px;">
        <div name="current">關閉當前選項卡</div>
        <div name="others">關閉其他選項卡</div>
        <div class="menu-sep"></div>
        <div data-options="iconCls:'icon-cancle'" name="all">關閉所有選項卡</div>
    </div>
</body>

本文永久更新連結地址:https://www.bkjia.com/Linux/2018-03/151118.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.