Have the following issue:
Trying to subclass fabric.Group:
var CustomGroup = fabric.util.createClass(fabric.Group, {
type : 'customGroup',
initialize : function(objects, options) {
options || ( options = { });
this.callSuper('initialize', objects, options);
this.set('customAttribute', options.customAttribute || 'undefinedCustomAttribute');
},
toObject : function() {
return fabric.util.object.extend(this.callSuper('toObject'), {
customAttribute : this.get('customAttribute')
});
},
_render : function(ctx) {
this.callSuper('_render', ctx);
}
});
Testcase:
I create a red rectangle and added it to the custom group:
function drawTestRect() {
// create a rectangle object
var rect = new fabric.Rect({
left : 100,
top : 100,
fill : 'red',
width : 20,
height : 20
});
var cgroup = new CustomGroup([rect], {
top : 50,
left : 50,
customAttribute : 'Hello World'
});
canvas.add(cgroup);
};
Problem:
I want to get JSON of the canvas and afterwards I want to load canvas from JSON.
drawTestRect()
var savedCanvas = canvas.toJSON();
canvas.clear();
canvas.loadFromJSON(savedCanvas);
Everything is working fine (Rect/Group is drawn; JSON is valid), but when I load from JSON, I get the following error in the console:
TypeError: Cannot read property 'async' of undefined
What I've tried yet:
- I added "CustomGroup.async = false;". But didn't help
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…