• extjs4.1单击treepanel节点收缩叶子节点


    表达的不是很清楚,就是树形菜单,有叶子节点,extjs默认的是双加节点才会收缩和伸展,其实实际中,都想使用方便一些,单击就可以展开叶子节点。如下图

    现在的画面中单击系统管理菜单可以收缩,再单击就会展开,很简单一个功能,但是很实用,主要是在treepanel的itemclick定义相关事件,如下:

      itemclick: function (tree, record, item, index, e, option) {
    
       if(record.get("leaf")==false)
    
         {          
    
               if (record.isExpanded()) {
                  record.collapse();
                } else {
                    record.expand();
                 }
                     return;
    
         }
    
    }
    View Code

    查看api其实可以指定,record是一个节点记录,具备treepanel的相关属性和事件,所以就好有上面的事件执行。完整代码如下(注意是放在Ext.onReady中):

        var store = Ext.create('Ext.data.TreeStore', {
                    root: {
                        expanded: true,
                        children: [{
                            id: "1001", text: "欢迎页面", leaf: true, url: "欢迎页面"
                        }, {
                            text: "系统管理", expanded: true,
                            children: [{
                                id: "1002", text: "角色管理", leaf: true, url: "角色管理"
                            }, {
                                id: "1003", text: "用户管理", leaf: true, url: "用户管理"
                            }]
                        }, {
                            text: "系统日志", leaf: true, url: "系统日志"
                        }]
                    }
                });
    
                var menuTree = Ext.create('Ext.tree.Panel', {
                    store: store,
                    listeners: {
                        itemclick: function (tree, record, item, index, e, option) {
                            if (record.get("leaf") == true) {
    
                                var tab = Ext.getCmp("tab" + record.get("id"));
                                if (tab) {
                                    tab.show();
                                }
                                else {
                                    tabPanel.add({
                                        id: "tab" + record.get("id"),
                                        closable: true,
                                        html: record.get("text"),
    
                                        title: record.get("text")
                                    }).show();
                                }
                            }
                            else {                         
                             
                                    if (record.isExpanded()) {
                                        record.collapse();
                                    } else {
                                        record.expand();
                                    }
                                    return;
                            
    
                            }
    
                        }
                    }
                });
    
                var tabPanel = Ext.create("Ext.tab.Panel", {
                    id: "centerTab",
                    items: [{
                        title: "欢迎",
                        id: "1000",
                        html: "欢迎你的到来"
                    }]
                });
    
                Ext.create("Ext.container.Viewport", {
                    layout: "border",
                    items: [{
                        region: "north",
                        title: "演示系统",
                        height: 100
                    }, {
                        region: "west",
                        title: "系统菜单",
                         200,
                        layout: "fit",
                        items: menuTree
                    }, {
                        region: "center",
                        layout: "fit",
                        border: false,
                        items: tabPanel
                    }]
                });
    View Code
  • 相关阅读:
    Linux 创建sftp用户并限制目录权限
    idea操作maven时控制台中文显示乱码/maven项目启动方式
    Docker 容器镜像删除
    Golang 在 Mac、Linux、Windows 下如何交叉编译
    Linux后台运行Jar方法
    MAC安装JDK及环境变量配置
    Docker 容器镜像删除
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
    《设计模式之禅》之状态模式
    《设计模式之禅》之访问者模式
  • 原文地址:https://www.cnblogs.com/mayantao/p/3317330.html
Copyright © 2020-2023  润新知