FabricJS - Error loading canvas from JSON

I am using a custom object extended from fabric.Image in my canvas, as suggested in this answer . When I retrieve the json string from the server, I get odd errors when trying to load it onto the canvas:

 var canvas = new fabric.Canvsd(); function loadCanvas(resp) { // response object contains a data field // that essentialy a JSON string var json = JSON.parse(resp.data); canvas.loadFromDatalessJSON(json); } 

I get an odd printout to the console: Cannot call method 'setupState' of undefined (fabric.min.js: 1118) . I tried replacing the canvas.loadFromJSON(json) call and instead got an undefined SyntaxError: Unexpected token o error. When I used regular fabric.Image before the change suggested in the linked thread, this code worked fine. I am afraid that this might be something that I missed when I expanded the favric Image with additional data. Thoughts?

+4
json canvas load fabricjs
Jul 02 2018-12-12T00:
source share
1 answer

After some searching, I saw a similar thread in the google fabricjs group. It turned out that I messed up 3 things:

  • I was unable to find the definition of the callback fromObject() elsewhere for another user object that I created (I had a couple).
  • I used loadFromDatalessJSON() when I should just use loadFromJSON() .
  • I parsed the json string in real JSON using JSON.parse(json) before passing it to the loadFromJSON() function, which was expecting the json string and processing the parsing inside.

Derp.

+2
Jul 02 '12 at 18:14
source share



All Articles