layui 格式化传出的日期格式

问题:在用以下语句将layui格式化传出的日期格式时
templet: "<div>{{ layui.laytpl.toDateString(d.checktime.time,'yyyy-MM-dd HH:mm:ss') }}</div>"

出现以下报错,主要原因是d.checktime为null,为了解决这个问题,想用函数来解决,如下:

templet: function(d){
    if (d.checktime == null)
    {
        return "";
    }
    return "<div>{{ layui.laytpl.toDateString(d.checktime.time,'yyyy-MM-dd HH:mm:ss') }}</div>";
}

结果仍然报错
解决办法:
如下图红色部分,用正规的templet语法来解决就可以了。

layui.use(['table','util', 'layer'], function () {
    var table = layui.table;
    var layer = layui.layer;
    var util = layui.util;

    //实例
    table.render({
        elem: '#demo',
        height: 523,
        url: basePath+'/rsshare/getData',//数据接口
        page: true,
        where: intParam(),
        limit: 10,
        cellMinWidth: 80, //全局定义常规单元格的最小宽度,layui 2.2.1 新增
        toolbar: '#toolbarDemo',
        defaultToolbar: ['filter', 'print', 'exports'],
        cols: [
            [ //表头
                {
                    type: 'checkbox',
                }, {
                field: 'id',
                title: '序号',
                width: 100,
                sort: true
            }, {
                field: 'rsname',
                title: '共享资源名称',
                sort: true,

            }, {
                field: 'status',
                title: '审核状态',
                sort: true,
                templet: function (d) {
                    if (d.status == 0) {
                        return "待审核";
                    } else {
                        return "已审核";
                    }
                }
            },{
                field: 'applytime',
                title: '申报时间',
                templet: "<div>{{ layui.laytpl.toDateString(d.applytime.time,'yyyy-MM-dd HH:mm:ss') }}</div>"
            },{
                field: 'checktime',
                title: '审核时间',
                templet: function(d){
                    if (d.checktime == null)
                    {
                        return "";
                    }
                    return util.toDateString(d.checktime.time, "yyyy-MM-dd HH:mm:ss");
                }
            }
            ]
        ]
    });
    //头工具栏事件
    table.on('toolbar(demo)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
            case 'detail':
                var data = checkStatus.data;
                if (data.length < 1) {
                    layer.alert('请选择一条数据', {icon: 5});
                } else if (data.length > 1) {
                    layer.alert('只能选择一条数据', {icon: 5});
                } else {
                    var action = basePath+"/busExamRecord/busExamRecordDetailList?recordId=" + data[0].id;
                    dataEdit(layer, table, action, "demo", intParam(), ['800px', '600px']);
                }
                break;
        }
        ;
    });
});
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

灰暗角落里的琴

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

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

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

打赏作者

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

抵扣说明:

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

余额充值