Metronic数据表-未捕获的TypeError:无法读取未定义的属性“类”

时间:2018-09-10 14:59:52

标签: ajax datatables metronic

我正在尝试按post_status列过滤列,但这给了我下面的错误

games:667 Uncaught TypeError: Cannot read property 'class' of undefined
at Object.template (games:667)
at HTMLTableCellElement.<anonymous> (scripts.bundle.js:1434)
at Function.each (vendors.bundle.js:362)
at jQuery.fn.init.each (vendors.bundle.js:157)
at HTMLTableRowElement.<anonymous> (scripts.bundle.js:1419)
at Function.each (vendors.bundle.js:362)
at jQuery.fn.init.each (vendors.bundle.js:157)
at Object.setupTemplateCell (scripts.bundle.js:1388)
at Object.insertData (scripts.bundle.js:1944)
at Object.afterGetData (scripts.bundle.js:1866)

这是post_status字段

field: "post_status",
title: "Status",

template: function (row) {
    var status = {
        1: {'title': 'pending', 'class': 'm-badge--brand'},
        2: {'title': 'published', 'class': ' m-badge--metal'},
    };
    console.log(row.post_status);
    return '<span class="m-badge ' + status[row.post_status].class + ' m-badge--wide">' + status[row.post_status].title + '</span>';
}

当我删除模板部分时,数据表也可以工作,但是当我添加模板部分时,它会出现上述错误。我无法通过post_status列过滤结果。如何解决此问题?

0 个答案:

没有答案