每当我尝试将舞台保存为JSON时,每个Konva文本都会被剪裁(删除所有空格),这是我的代码:
var exportObj = stage.toJSON();
console.log(exportObj);
$("<a />", {
"download": "yearBook.yrb",
"href" : "data:application/json," + exportObj,
}).appendTo("body")
.click(function() {
console.log("save");
$(this).remove();
})[0].click();
答案 0 :(得分:0)
我认为这是因为将JSON数据插入HTML(到DOM属性href
)。
尝试将此用于'href'属性:
"data:application/json;base64," + btoa(unescape(encodeURIComponent(exportObj)))
var exportObj = stage.toJSON();
console.log(exportObj);
$("<a />", {
"download": "yearBook.json",
"href" : "data:application/json;base64," + btoa(unescape(encodeURIComponent(exportObj))),
}).appendTo("body")
.click(function() {
console.log("save");
$(this).remove();
})[0].click();