我目前使用tabulator library基于json数据创建表。 我正在尝试使用自定义单元格格式化程序将按钮添加到单元格中。
这是我的方法:
var graphButton = function(cell, formatterParams, onRendered){
var button = '<button onclick="customMethod(cell.getRow().getData())">myLabel</button>';
return button;
};
然后,我将 graphButton
传递到表的定义中。
按钮显示正确。但是,当我单击该按钮时,收到一条错误消息:找不到变量:单元格
。
如何正确地将单元格变量传递到 customMethod
中?
最佳答案
尝试使用这种方式不确定,但根据标准这将是可行的
var graphButton = function(cell, formatterParams, onRendered) {
var button = `<button onclick="customMethod('${cell.getRow().getData()}')">myLabel</button>`;
return button;
};
关于javascript - 如何将变量传递到 html 元素中的 onclick 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57691904/