我正在使用 Tabulator 来管理一些表格,我已经了解了如何以 JSON 格式和其他格式下载文件,但我想知道是否包含将数据保存在 JSON 对象中的功能,以便我可以将其直接上传到服务器
我已经查看了此页面 http://tabulator.info/docs/4.1/download我想到了使用“Custom File Formatter”然后拦截下载 bolb 但我一直收到错误指的是
setFileContents(names.join(", "), "text/plain");
Uncaught ReferenceError: setFileContents is not defined
函数代码:
document.querySelector("#uploadJSON").onclick = function(){
var fileFormatter = function(columns, data, options){
var names = [];
data.forEach(function(row){
names.push(row.name);
});
setFileContents(names.join(", "), "text/plain");
}
table.download(fileFormatter, "test.json");
}
最佳答案
您可以使用getData 函数获取行数据对象数组:
var data = table.getData();
然后使用 stringify 函数对其进行 JSON 编码:
var jsonData = JSON.stringify(data);
然后由您来选择如何将其上传到服务器,实际上有几个 ajax 库甚至会为您进行 JSON 编码,因此您只需要将 getData函数
关于javascript - 制表符将 JSON 上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53506254/