Extjs4.0.7 tree 結構讀取json檔案(在架構viewport中)__div

來源:互聯網
上載者:User

test.json 檔案

{children:[
{id:'01',text:'a01',children:[
{id:'01-01',text:'a01-01',leaf:true},
{id:'01-02',text:'a01-02',children:[
{id:'01-02-01',text:'b01-02-01',leaf:true},
{id:'01-02-02',text:'a01-02-02',leaf:true}
]},
{id:'01-03',text:'b01-03',leaf:true}
]},
{id:'02',text:'b02',leaf:true}
]}


css樣式:(注意傳參數時leaf:'true'紅色部分必須小寫,不知什麼原因,大寫不起做用)

/*為節點的開閉狀態和分葉節點狀態分別設定樣式*/
 /* 如果沒有.x-tree-icon-parent 將沒有展開的後的表徵圖,(展開和不展開表徵圖一樣)*/
.x-grid-tree-node-expanded  .x-tree-icon-parent{width:16px;background-image: url(../Images/icons/v3_expanded.ico)!important;}    

.x-tree-icon-parent{width:16px;background-image: url(../Images/icons/v3_collapsed.ico)!important;}    
.x-tree-icon-leaf{width:16px;background-image:url(../Images/icons/edit.png)!important;} 

viewport_tree.js

//--------------------------------------定義上邊 top表單----------------------------

var north=new Ext.Panel({
                        title: 'north',
                        region: 'north',
                        split: true,
                        border: true,
                        collapsible: true,
                        height: 80,
                        minSize: 100,
                        maxSize: 120
    }); //--------------------------------------定義右邊 east表單----------------------------

var east=new Ext.Panel({
                        title: 'east',
                        region: 'east',
                        split: true,
                        border: true,
                        collapsible: true,
                        width: 100,
                        minSize: 100,
                        maxSize: 120
    });

//--------------------------------------定義下邊south表單----------------------------

var south=new Ext.Panel({
                        title: 'south',
                        region: 'south',
                        split: false,
                        border: true,
                        height:80,
                        collapsible: true
    });

//--------------------------------------定義左邊 west 表單----------------------------

var treeStore1 = Ext.create('Ext.data.TreeStore', {
        autoLoad : true,
        proxy: {
            type: 'ajax',
            url: 'test.json.json',
            reader: {
                type: 'json',
                root: 'children'
                //record: 'node'
            }
        },
        sorters: [{
            property: 'leaf',
            direction: 'ASC'
        }],
        root: {
            nodeType: 'async',
            text: 'Ext JS',
            //id: '00',
            expanded: true
        }
    });


var treepanel1 = Ext.create('Ext.tree.TreePanel', {
    //如果超出範圍帶自動捲軸
    autoScroll:true,
    //animate:true,
    //root:root,
    //預設根目錄不顯示
    rootVisible:true,
    border:false,
    animate:true,
    lines:true,
    //enableDD:true,
    height:600,
    store:treeStore1
    //width: 500
    //containerScroll:true   
    });

var treepanel2 = Ext.create('Ext.tree.Panel', {
        //title: '簡單的樹形組件',
        store: treeStore1,
        animate:true,
        autoScroll:true,  //如果超出範圍帶自動捲軸
        width: 500,
        height:400,
        border:true,    //顯示tree side frame
        //資料容器
        //loader:new Ext.tree.TreeLoader({url:"web/MenuTree.json"}),
        rootVisible: true,  //是否顯示根節點
       // renderTo: Ext.getBody()
        containerScroll:true,
        listeners: {
            'itemclick': function (view, record) {
                    var leaf = record.get('leaf');
                    if (leaf) {
                       alert('is leaf!');
                        var id = record.get('id');
                        var text = record.get('text');
                        var tabPanel = Ext.getCmp('MAINPANEL');
/*
                    var tab = tabPanel.getComponent(id);
                    if (!tab) {
                        tabPanel.add(Ext.create('Tesz.App.Panels.' + id)).show();
                    }
                    tabPanel.setActiveTab(tab);
*/
                    }
                    else {
                        alert('not leaf!');
                        var expand = record.get('expanded')
                        if (expand) {
                            view.collapse(record);
                        }
                        else {
                            view.expand(record);
                    }
                }
            }
        }  //listeners -------funcation end----------
    });

var west=new Ext.Panel({
                        collapsible:true,   //自動收縮按鈕
                        split: true,
                        border:false,
                        width:225,
                        layout:"accordion",
                        //extraCls:"roomtypegridbbar",  //添加動畫效果
                        layoutConfig: {
                               animate: true
                         },
                        region:"west",
                        title:'威威系統',
                        items:[{
                            title:"<b>生產系統模組</b>",
                            autoScroll:true,
                            items:[treepanel2],
                            iconCls:"hotelmanageicon"
                        },{
                            title:"<b>人事薪資系統模組</b>",
                            autoScroll:true,
                            iconCls:"hotelmanageicon"
                            //items:[treenode]
                        },{
                            title:"<b>OA系統模組</b>",
                            autoScroll:true,
                            iconCls:"hotelmanageicon"
                            //items:[treenode]
                        },{
                            iconCls:"gonggao",
                            title:"<b><span style='color:red';>Hotel Notice</span></b>"
                            //items:[publishinfosgrid]
                        }]
    });

//------------------------------------------程式開始-------------------------------------
Ext.onReady(function () {
    //定義樹形組件
    //Ext.Msg.alert('提示資訊', '學習EXTJS');

    var vp=new Ext.Viewport({
        layout:"border",
        items:[north, east, west, center, south]
    });
});

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.