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
InformationsquelleAutor mahega | 2014-06-24
Schreibe einen Kommentar