I have a canvas where I am drawing grid lines using the line drawing method of fabric.js. I am defining selection property of those lines as false while drawing which works fine as expected. Now when I stringify the canvas and retrieve the JSON output I noticed that rest of the properties were extracted except the selection property. What do I need to do to keep the selection property intact in the JSON? I am using fabric.js-1.4.10
You can go with following code and you will have all additional properties when you will call toJSON() method :
var obj = fabric.util.groupSVGElements(objects, options).set({
top: 0,
left: 0
});
obj.toJSON = (function (toJSON) {
return function () {
return fabric.util.object.extend(toJSON.call(this), {
customProperties: this.customProperties
});
};
})(obj.toJSON);
Actually as @Abhishek has said in comment than fabric's toJSON() method or any other method that is used to export svg will export only default properties of fabric object. If you want to get your custom added property in export list than you need to override toJSON method as i did in above code, than after when you will use toJSON() method, you will have customproperty in exported JSON.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With