Reputation: 1321
This is a json
{"objects":[{"type":"image","originX":"center","originY":"center","left":379,"top":136,"width":2000,"height":2000,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.1,"scaleY":0.1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","src":"http://localhost/kraftkadev/uploaded/shop/sticker-1.png","filters":[],"crossOrigin":""},{"type":"image","originX":"center","originY":"center","left":269,"top":299,"width":2000,"height":2000,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.1,"scaleY":0.1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","src":"http://localhost/kraftkadev/uploaded/shop/sticker-1.png","filters":[],"crossOrigin":""}],"background":""}
This is my JSON file but it just shows the first image not second one & gives error as "Uncaught TypeError: Cannot read property 'set' of undefined"
I used Fabric.js loadFromJSON() function to load json to canvas. I also used below syntax but it does not help either.
canvas.loadFromJSON(json,canvas.renderAll.bind(canvas));
Upvotes: 2
Views: 2498
Reputation: 1321
I got the answer for it. Actually if we have image inside the canvas then it will take time to load & before loading we are setting it as active element, because of this it give error. So just check whether it is loaded or not & if not loaded then don`t make it as active element.
if(e) {
//make it as active element
}
Upvotes: 1