ExtJS中給Tree節點加click事件

來源:互聯網
上載者:User

標籤:blog   http   io   os   ar   使用   strong   sp   on   

第一種:

       直接通過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

 

ExtJS中給Tree節點加click事件

聯繫我們

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