如何在创建Tabulator实例后设置回调



我正在使用Tabulator,并希望侦听表编辑事件。我检查了回调dataEdited,发现所有的例子都在创建实例时设置了回调函数,比如new Tabulator('#samplediv',{dataEdited:function(({…}}(

然而,我需要在创建实例后在子函数中设置回调,如:

const table=new Tabulator(......)
function SomeSub(){
// how to set dataEdited of table here?
}

我尝试了table.dataEdited=function(({},但它不起作用。

我不知道对于一个熟练的程序员来说,这是否是一个真正的问题,但它真的让我很困惑。非常感谢你的评论。

在Tabulator中实例化回调后,您不能更改它,但您可以简单地从回调内部调用另一个函数。

如果您只想跟踪用户编辑,而不是对数据的所有更改,那么cellEdited回调可能是更合适的选择。

function externalFunction(cell){
do a thing;
}
var table = new Tabulator("#example-table", {
cellEdited:function(cell){
externalFunction(cell);
},
});

如果你想改变被调用函数的性质,那么你可以在一个外部对象上添加函数,然后随时改变它。

//define initial function holding object
var functionHolder = {
externalFunction:function (cell){
do a thing;
}
}
//create your table
var table = new Tabulator("#example-table", {
cellEdited:function(cell){
functionHolder.externalFunction(cell);
},
});
//...
//some time later redefine the function
functionHolder.externalFunction = function(cell){
//do something different
}

最新更新