I have a rect A with the custom property "childs", this property is an array to which I put rects B. The rect B has a custom property "another".
The problem is that after serializing the canvas and loading the json on the canvas, the event listener does not load the property "another" of the rect B.
Here you can see the problem better: https://jsfiddle.net/ps7566/y3k5b4c1/
var a = new fabric.Rect({
left: 70,
top: 70,
fill: 'blue',
width: 100,
height: 100
});
var b = new fabric.Rect({
left: 75,
top: 75,
fill: 'red',
width: 50,
height: 50
});
b.another = 'property';//this custom property is losed in event observer after serialize
a.childs = [];
a.childs.push(b);
canvas.add(a);
canvas.observe("mouse:up",function(e){
if(e.target != null){
console.log(e.target);
alert(e.target.childs[0].another);
//why this is undefined after serialize and load json?
}
});
function serialize(){
json = JSON.stringify(canvas.toJSON(['childs','another']));
}
function loadJSON(){
canvas.loadFromJSON(json);
}
I want that the event listener can access the property "another" even after loading a JSON.