layui table 列属性 edit 可判断是否有权限修改方案

layui 中 table组件里面的 列属性有一个 edit

这个edit 只有一个固定值 text

 

但是如果我们有一个列表

有些行可以修改 有些又不能修改

这个时候就需要重造此方法了

原始代码 此为 table 中的 td 点击事件处理

 i.layBody.on("click", "td", function (e) { var i = t(this), a = (i.data("field"), i.data("edit")), l = i.children(h); if (!i.data("off") && a) { var n = t(''); return n[0].value = i.data("content") || l.text(), i.find("." + R)[0] || i.append(n), n.focus(), void layui.stope(e) } }).

 

修改为

i.layBody.on("click", "td", function (e) {
            var b = t(this), a = (b.data("field"), b.data("edit")), l = b.children(h),n = b.parents("tr").eq(0).data("index");
            var itemData = d.cache[i.key][n];
            if(isExitsFunction(a)){
                var func = eval(a);
                a = func(itemData);
            }
            if (!b.data("off") && a) {
                var n = t('<input class="layui-input ' + R + '">');
                return n[0].value = b.data("content") || l.text(), b.find("." + R)[0] || b.append(n), n.focus(), void layui.stope(e)
            }
        })

其中 设置edit:"checkEditAuth" 需要为函数名 且挂载在window中

function checkEditAuth(d){

return d.staff_id == <?=Yii::$app->user->getId()?>;
}

修改代码如下

layui table 列属性 edit 可判断是否有权限修改方案

给TA打赏
共{{data.count}}人
人已打赏
PHP技术技巧

php 7.2 xdebug 3.0.1 跟 mysqli_affected_rows 冲突 导致返回 -1

2021-2-23 11:14:35

PHP技术技巧

yii2 console sooole中多进程 mysql has gone away

2021-5-27 10:46:48

0 条回复A文章作者M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索