Fabric.js Unterklassen Stoff.Gruppe - Fehler: "Cannot read property 'async' of undefined" beim laden von JSON
Haben das folgende Problem:
Versucht Unterklasse Stoff.Gruppe:
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:
Erstelle ich ein rotes Rechteck und fügte zu der benutzerdefinierten Gruppe:
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:
Ich möchte JSON-auf der Leinwand und später will ich Last Leinwand von JSON.
drawTestRect()
var savedCanvas = canvas.toJSON();
Leinwand.clear();
Leinwand.loadFromJSON(savedCanvas);
Alles ist in Ordnung (Rect/Gruppe gezogen wird; JSON Valide ist), aber wenn ich laden von JSON, bekomme ich die folgende Fehlermeldung in der Konsole:
TypeError: Cannot read property 'async' undefined
, Was ich versucht habe, noch:
- Ich fügte hinzu, "CustomGroup.async = false;". Aber hat auch nicht geholfen
Du musst angemeldet sein, um einen Kommentar abzugeben.
Den Fehler "Cannot read property 'async' of undefined" wird erhöht, da keine "klass" gefunden werden kann - https://github.com/kangax/fabric.js/blob/master/src/util/misc.js#L214-215.
Ordnen Sie Ihre benutzerdefinierten Objekts
fabric
Objekt - sonstcanvas.loadFromJSON()
funktioniert nicht.Zusätzlich müssen Sie deklarieren die
fromObject
Methode - es ist notwendig fürloadFromJSON
.In diesem Fall besteht das Objekt geladen ist synchron.
Wenn das benutzerdefinierte Objekt geladen wird, async, die Sie haben, dies zu tun:
Habe ich eine kleine jsfiddle testcase: http://jsfiddle.net/Kienz/qPLY6/
fromObject
Hinzugefügt werden sollten, die Subclassing - Dokumentation auf fabric.js