Fabric.js - how to save canvas on server with custom attributes

后端 未结 5 1713
梦毁少年i
梦毁少年i 2020-11-27 09:45

I\'d like to be able to save the current canvas\' state to a server-side database, probably as a JSON string, and then later restore it with loadFromJSON. Typic

5条回答
  •  暖寄归人
    2020-11-27 10:28

    A more simple approach would be to add the properties post-stringify:

    var stringJson = JSON.stringify(this.canvas);
    var objectJson = JSON.parse(string.Json);
    
    //remove property1 property
    delete objectJson.property1;
    
    //add property2 property
    delete objectJson.property2;
    
    // stringify the object again
    stringJson = JSON.stringify(objectJson);
    
    // at this point stringJson is ready to be sent over to the server
    $http.post('http://serverurl/',stringJson);
    

提交回复
热议问题