ExtJS中給Tree節點加click事件


第一種:

       直接通過TreePanel中的Config Option中的listener來添加,代碼如下:

    var TreePan = new Ext.tree.TreePanel({

        id: 'TreePan',

        title: "側邊欄",

        useArrows: true,

        width: 240,

        height: 660,

        region: 'west',

        frame: true,

        autoScroll: true,

        enableDD: false,

        containerScroll: true,

        draggable: false,

        root: root,

        rootVisible: false,

        collapsible: true,

        collapsed: true,

        animate: true,

        listeners: {

            'click': function(node, e) {

                if (node.isLeaf()) {

                    var newWin = new Ext.Window({

                        width: 745,

                        height: 529,

                        title: "現用技術標准",

                        html: "<iframe src=/"Manage/VolunteerShipInfo.aspx/" marginheight=/"0/" marginwidth=/"0/" width=/"727/" height=/"500/"></iframe>"

                    });

                    newWin.show();

                }

            }       

 }

 

失敗,表現為程序對 “node.isLeaf()”這個方法的識別有問題,加上這條if語句,則點擊所有節點沒反應(包括非葉節點);去掉這個if,則點所有節點都會出現新窗口(包括非葉節點)。

 

     第二種:

     使用TreePan.on來添加Event,代碼如下:

 

    var TreePan = new Ext.tree.TreePanel({

        id: 'TreePan',

        title: "側邊欄",

        useArrows: true,

        width: 240,

        height: 660,

        region: 'west',

        frame: true,

        autoScroll: true,

        enableDD: false,

        containerScroll: true,

        draggable: false,

        root: root,

        rootVisible: false,

        collapsible: true,

        collapsed: true,

        animate: true, 

 }

TreePan.on('click', BiaoZhunClick);

 

    function BiaoZhunClick(node, e) {

        if (node.leaf) {

            //            e.stopEvent();

            var newWin = new Ext.Window({

                width: 745,

                height: 529,

                title: "現用技術標准",

                html: "<iframe src=/"Manage/VolunteerShipInfo.aspx/" marginheight=/"0/" marginwidth=/"0/" width=/"727/" height=/"500/"></iframe>"

            });

            newWin.show();

        }

    }

 

失敗,表現如方法二。

 

     第三種:

     通過查API Document,知道可以用addListener這個方法來給TreePanel添加Event,於是嘗試如下:

 

    var TreePan = new Ext.tree.TreePanel({

        id: 'TreePan',

        title: "側邊欄",

        useArrows: true,

        width: 240,

        height: 660,

        region: 'west',

        frame: true,

        autoScroll: true,

        enableDD: false,

        containerScroll: true,

        draggable: false,

        root: root,

        rootVisible: false,

        collapsible: true,

        collapsed: true,

        animate: true, 

 }

    TreePan.addListener('click', BiaoZhunClick);

    function BiaoZhunClick(node, e) {

        if (node.leaf) {

            //            e.stopEvent();

            var newWin = new Ext.Window({

                width: 745,

                height: 529,

                title: "現用技術標准",

                html: "<iframe src=/"Manage/VolunteerShipInfo.aspx/" marginheight=/"0/" marginwidth=/"0/" width=/"727/" height=/"500/"></iframe>"

            });

            newWin.show();

        }

    }

 

成功,終於可以實現只有在點擊葉節點時才彈出浮窗了。

 轉自:http://blog.csdn.net/scythev/article/details/4818610

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM