layui table radio回显选中,layui列表单选或复选回显选中,layui列表radio回显选中

本文详细介绍了如何使用layui框架在表格中回显已选择的用户列表,通过在table的done回调函数中进行列表单选选中的回显操作,实现了用户列表与合同关联用户的同步显示。代码示例清晰,直接复制即可使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.效果描述:

查看该合同关联用户列表时,在列表中回显选中该合同已经关联的用户

DESC:以下均为layui原生代码完全可以直接复制

2.效果图:

弹出对话框,一个页面(里面是用户列表)

3.layui渲染table的代码:

我们的目标是在table的done回调函数中进行列表单选选中的回显操作,(最重要的就是第32和33行代码)

  var formHeight = $("#user-search-form").height();
    table.render({
      elem: '#user-table',
      url: config.base_server + config.route_user + '/user/v1/unauthorityuserlist',
      where: {
        userId: setter.getUser().userId,
        access_token: config.getToken().access_token,
        parentId: setter.getUser().organId
      },
      page: true,
      height: 'full-' + (70 + formHeight),
      cols: [[
        {type: 'radio'},
        {title: '序号', type: 'numbers'},
        {field: 'userId', hide: true},
        {field: 'appIdentification', hide: true},
        {field: 'appName', hide: true},
        {field: 'orgName', hide: true},
        {field: 'orgNo', hide: true},
        {field: 'userName', sort: true, title: '账号', width: 150},
        {field: 'name', sort: true, title: '用户名'},
        {align: 'center', toolbar: '#user-table-bar', width: 200, title: '操作', fixed: 'right'}
      ]],
      done: function (res, curr, count) {

        //看这里
        //利用回调函数进行回显
        var dataArr = res.data;
        for (var i = 0; i < dataArr.length; i++) {
            //如果符合条件那么点击选中
          if (dataArr[i].userId == t_contract.USERID) {
            $('div.layui-unselect.layui-form-radio')[i].click();//单选用这个
            //复选用这个 : $('div.layui-unselect.layui-form-checkbox')[(i+1)].click();
            break;
          }

        };
        //form.render();
      }
    });

4.参考博客:

layui table 点击行时选中 单选框_layui数据表格点击行选中单选框_ohmorning的博客-优快云博客

5.太懒了,就为这个回显一直在百度,不想动脑子,但是没办法,网上没有现成的例子或者layui现成的方法,只能自己去参考然后再写了,我想睡会儿...好累啊~

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

法国红酒洗大虾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值