对于Slickgrid,
通常,您可以在dateFormatter
变量中像这样设置回调columns
。
var columns = [
{id: "finish", name: "Finish", field: "finish",
formatter: dateFormatter, // path callback name to table
sortable: true }
];
function dateFormatter(row, cell, value, columnDef, dataContext) {
return value.getMonth() + '/' + value.getDate() + '/' + value.getFullYear();
}
现在,我制作了包含与处理表有关的成员和方法的类。
然后,我想在类方法中捕获dateFormatter
回调。如何设置回调?
class Table{
constructor(){
this.columns = [
{ id: "finish", name: "Finish",
field: "finish",
formatter: `this.dateFormatter`}, // it doesn’t work
];
this.data = new Array();
this.dataView = new Data.DataView();
this.grid;
}
makeGrid(gridName){
this.grid = new Grid(gridName,
this.dataView,
this.columns,
this.options);
}
dateFormatter(row, cell, value, columnDef, dataContext) { // want to catch here.
return value.getMonth() + '/' + value.getDate() + '/' + value.getFullYear();
}
}
答案 0 :(得分:1)
您正在尝试将函数引用作为模板文字字符串传递。
更改
formatter: `this.dateFormatter`
收件人
formatter: this.dateFormatter
答案 1 :(得分:1)
在您的构造函数中:
this.columns = [
{ id: "finish", name: "Finish",
field: "finish",
formatter: this.dateFormatter} // no need for back-ticks
];
不需要back ticks
中的this.dateFormatter
,它将转换为字符串。