为 class 方法设置回调
Set callback for class method
对于 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();
}
现在我创建了class,其中包含与处理table相关的成员和方法。
然后,我想在 class 方法中捕获 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
在你的构造函数中:
this.columns = [
{ id: "finish", name: "Finish",
field: "finish",
formatter: this.dateFormatter} // no need for back-ticks
];
this.dateFormatter
中不需要 back ticks
,这会将其转换为字符串。
对于 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();
}
现在我创建了class,其中包含与处理table相关的成员和方法。
然后,我想在 class 方法中捕获 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
在你的构造函数中:
this.columns = [
{ id: "finish", name: "Finish",
field: "finish",
formatter: this.dateFormatter} // no need for back-ticks
];
this.dateFormatter
中不需要 back ticks
,这会将其转换为字符串。