我正在尝试按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列过滤结果。如何解决此问题?