zoukankan      html  css  js  c++  java
  • easyui_动态添加隐藏toolbar按钮

    目标:动态添加隐藏toolbar,比如根据权限动态显示新增、修改、删除按钮等

    思路:先初始化toolbar的所有按钮,加载datagrid其它信息,再根据权限显示隐藏toolbar按钮

    步骤:
    1、加载步骤
    1
    2
    3
    4
    5
    $(function() {
        easyToolbarInit();     //初始化toolbar按钮
        easyInitGrid({title:"管理",url:"/sa/add"});  //加载datagrid其它信息,如列等
        easyToolbarDisplay();  //根据权限显示/隐藏 toolbar按钮  张         
    });


    2、初始化toolbar按钮(按钮的id为后面使用的标识信息,这里最好用完整信息,防止和其它id冲突​)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    //初始化toolbar按钮
    function easyToolbarInit() {
         
        $('#grid').datagrid({
            toolbar : [ {
                id : 'add',    
                text : '添加',
                iconCls : 'icon-add',
                height : 50,
                handler : function() {
                    gridAdd();
                }
            }, '-', {
                id : 'delete',
                text : '删除',
                iconCls : 'icon-remove',
                height : 50,
                handler : function() {
                    gridDelete();
                }
            } ]
        });
    }

    3、加载datagrid其它信息


    4、根据权限显示/隐藏 toolbar按钮  

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    function easyRightDisplay() {
        //获取所有的toolbar按钮
        var button=$('div.datagrid div.datagrid-toolbar a');
        for (var i = 0; i < button.length; i++) {
            var toolbar = button[i];
            var id = toolbar.id;
            if (id == "add") {  //隐藏Id为add的按钮
                $('div.datagrid div.datagrid-toolbar a').eq(i).hide();
            }
            if (id == "delete") {  //不隐藏id为delete的按钮
                //button.eq(i).hide();
            }
            //如果按钮都没权限,隐藏了可直接隐藏toolbar
            //$('div.datagrid div.datagrid-toolbar').hide();
        }





  • 相关阅读:
    cookie实例---显示上一次访问的时间与java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
    No Mapping For GET "xxx.do"
    Mybatis 配置文件
    spring整合JUnit测试
    Spring 约束文件配置
    c3p0封装
    Linux下载:wget、yum与apt-get用法及区别
    docker安装各种坑
    动态管理upsteam---nginx_http_dyups_module
    安装nginx环境(含lua)时遇到报错ngx_http_lua_common.h:20:20: error: luajit.h: No such file or directory的解决
  • 原文地址:https://www.cnblogs.com/gossip/p/5439984.html
Copyright © 2011-2022 走看看