Layui表格列添加超链接

记录一下,需要用到templet属性,也就是自定义列模板

参考代码:

{ field: 'oddNumbers', width: 180, title: '单号', sort: true, fixed: 'left', templet: addLink },

addLink是个方法

function addLink(d) {
  var addLink = d.oddNumbers;
   if ('' == addLink || null == addLink || undefined == addLink) {
        return '';
   }
   if (addLink.length > 0) {                  
        return '<a class="layui-table-link" href="javascript:void(0);" lay-event="link">' + d.oddNumbers + '</a>';                  
   }
}        

layui 2.2.5 开始,templet 开始支持函数形式,函数返回一个参数 d,包含接口返回的所有字段和数据。

参考链接https://www.layui.com/demo/table/style.html  https://www.layui.com/doc/modules/table.html#templet

这样界面就有超链接了,如下图

一般链接会打开一个tabs或弹窗或者其它,我用的弹窗,监听表格行,获取点击行数据,如下

 table.on('tool(pcList)', function (obj) {
      var checkStatus = obj.data;
      var url = checkStatus.oddNumbers;
      url = encodeURIComponent(url);
      console.log(checkStatus.oddNumbers);//单号
      layer.open({
           type: 2,
           title: '账票详细',
           shadeClose: true,
           shade: 0.8,
           area: ['60%', '90%'],
           content: 'newList.html?'+url 
      });
 });

这样就ok了。

posted @ 2020-09-20 23:33  exception_ex  阅读(6038)  评论(0编辑  收藏  举报