对于 Slickgrid,
通常,您可以在columns
变量中设置回调dateFormatter
。
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();
}
}
最佳答案
您正在尝试将函数引用作为模板文字字符串传递。
改变
formatter: `this.dateFormatter`
至
formatter: this.dateFormatter
关于javascript - 设置类方法的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53205900/