Anytime I try to do Konva.Node.create, I get an error: "Uncaught TypeError: Cannot set property 'container' of undefined". As far as I can tell, the data I am using is properly formatted JSON, saved to and then retrieved from a file after using toJSON on an initial stage. I would greatly appreciate any help in solving this. I have posted the console log of the data below, thanks!:
{
"attrs[width]": "754",
"attrs[height]": "647",
"className": "Stage",
"children[0][className]": "Layer",
"children[0][children][0][attrs][rotateEnabled]": "false",
"children[0][children][0][attrs][enabledAnchors][]": [
"top-left",
"top-right",
"bottom-left",
"bottom-right",
],
"children[0][children][0][className]": "Transformer",
"children[0][children][1][attrs][draggable]": "true",
"children[0][children][1][attrs][id]": "square1",
"children[0][children][1][className]": "Group",
"children[0][children][1][children][0][attrs][x]": "559",
"children[0][children][1][children][0][attrs][y]": "342.5",
"children[0][children][1][children][0][attrs][name]": "Square",
"children[0][children][1][children][0][attrs][width]": "100",
"children[0][children][1][children][0][attrs][height]": "100",
"children[0][children][1][children][0][attrs][fill]": "white",
"children[0][children][1][children][0][attrs][stroke]": "black",
"children[0][children][1][children][0][className]": "Rect",
"children[0][children][1][children][1][attrs][name]": "text",
"children[0][children][1][children][1][attrs][text]": "Storage",
"children[0][children][1][children][1][attrs][align]": "center",
"children[0][children][1][children][1][attrs][verticalAlign]": "middle",
"children[0][children][1][children][1][attrs][x]": "559",
"children[0][children][1][children][1][attrs][y]": "382.5",
"children[0][children][1][children][1][attrs][fontSize]": "15",
"children[0][children][1][children][1][attrs][width]": "100",
"children[0][children][1][children][1][attrs][fill]": "black",
"children[0][children][1][children][1][className]": "Text",
}
Here is the method loadStage that throws the error. I save the code to a JSON file, and retrieve it using node. It is then passed to the function here:
function loadStage(stage) {
$.ajax({
type: 'GET',
//contentType: 'application/json',
url: '/getstage',
success: function (data) {
console.log("'"+data+"'");
if(data !== "")
{
stage = Konva.Node.create(data, 'canvas');
}
}
});
}
Here is the method that saves the code on update (when I add a new shape):
function saveStage() {
var json = stage.toJSON();
$.ajax({
type: 'POST',
//contentType: 'application/json',
data: JSON.parse(json),
url: '/savestage',
success: function (data) {
}
});
}
And the error message:
Uncaught TypeError: Cannot set property 'container' of undefined
at Function.ct._createNode (konva.min.js:12)
at Function.ct.create (konva.min.js:12)
at Object.success (facilitytracker.js:46)
at c (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at l (jquery.min.js:2)
at XMLHttpRequest.<anonymous> (jquery.min.js:2)
ct._createNode @ konva.min.js:12
ct.create @ konva.min.js:12
success @ facilitytracker.js:46
c @ jquery.min.js:2
fireWith @ jquery.min.js:2
l @ jquery.min.js:2
(anonymous) @ jquery.min.js:2
load (async)
send @ jquery.min.js:2
ajax @ jquery.min.js:2
loadStage @ facilitytracker.js:38
(anonymous) @ facilitytracker.js:9
e @ jquery.min.js:2
t @ jquery.min.js:2
setTimeout (async)
(anonymous) @ jquery.min.js:2
c @ jquery.min.js:2
fireWith @ jquery.min.js:2
fire @ jquery.min.js:2
c @ jquery.min.js:2
fireWith @ jquery.min.js:2
ready @ jquery.min.js:2
B @ jquery.min.js:2