admin管理员组文章数量:1022834
I am trying to import multiple svg file and after modification saving the json to database. I have tried to use
canvas.item(0).sourcePath = '/URL/FILE.svg';
JSON.stringify(canvas.toDatalessJSON());
but this won't work for multiple files, it works for the first file only. i am trying to specify every single file url but can't understand how this can be done. any solution please?
thanks in advance
I am trying to import multiple svg file and after modification saving the json to database. I have tried to use
canvas.item(0).sourcePath = '/URL/FILE.svg';
JSON.stringify(canvas.toDatalessJSON());
but this won't work for multiple files, it works for the first file only. i am trying to specify every single file url but can't understand how this can be done. any solution please?
thanks in advance
Share Improve this question edited Apr 2, 2013 at 11:41 rafi asked Apr 2, 2013 at 11:34 rafirafi 1,5533 gold badges31 silver badges44 bronze badges1 Answer
Reset to default 5canvas.item(0) - gets the first object. canvas.item(1) - gets the second object and so on....
If you don't know the total amount of objects you can use the canvas.forEachObject option.
canvas.forEachObject(function(obj){
obj.sourcePath = '/URL/FILE.svg';
console.log(obj.sourcePath)
});
JSON.stringify(canvas.toDatalessJSON());
You could also set obj.sourcePath when you load the svg like this.
fabric.loadSVGFromString(svg, function(objects, options) {
var obj = fabric.util.groupSVGElements(objects, options);
obj.sourcePath = '/URL/FILE.svg';
canvas.add(obj);
canvas.renderAll();
});
Hope that helps!
I am trying to import multiple svg file and after modification saving the json to database. I have tried to use
canvas.item(0).sourcePath = '/URL/FILE.svg';
JSON.stringify(canvas.toDatalessJSON());
but this won't work for multiple files, it works for the first file only. i am trying to specify every single file url but can't understand how this can be done. any solution please?
thanks in advance
I am trying to import multiple svg file and after modification saving the json to database. I have tried to use
canvas.item(0).sourcePath = '/URL/FILE.svg';
JSON.stringify(canvas.toDatalessJSON());
but this won't work for multiple files, it works for the first file only. i am trying to specify every single file url but can't understand how this can be done. any solution please?
thanks in advance
Share Improve this question edited Apr 2, 2013 at 11:41 rafi asked Apr 2, 2013 at 11:34 rafirafi 1,5533 gold badges31 silver badges44 bronze badges1 Answer
Reset to default 5canvas.item(0) - gets the first object. canvas.item(1) - gets the second object and so on....
If you don't know the total amount of objects you can use the canvas.forEachObject option.
canvas.forEachObject(function(obj){
obj.sourcePath = '/URL/FILE.svg';
console.log(obj.sourcePath)
});
JSON.stringify(canvas.toDatalessJSON());
You could also set obj.sourcePath when you load the svg like this.
fabric.loadSVGFromString(svg, function(objects, options) {
var obj = fabric.util.groupSVGElements(objects, options);
obj.sourcePath = '/URL/FILE.svg';
canvas.add(obj);
canvas.renderAll();
});
Hope that helps!
本文标签: javascriptSaving JSON in canvas with fabricjsStack Overflow
版权声明:本文标题:javascript - Saving JSON in canvas with fabric.js - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745524185a2154449.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论