2016-06-24 16 views
0

fabricjs canvasイメージを名前で取得するには、このiamgeに一意のIDまたは名前を設定する必要があります。私は新しいクラスを作成しましたfabric.NamedImage それは私がそれをした方法です。fabricjsオブジェクトに名前を追加する方法は?

fabric.NamedImage = fabric.util.createClass(fabric.Image, { 

    type: 'nameimage', 

    initialize: function (element, options) { 
     this.callSuper('initialize', element, options); 
     options && this.set('name', options.name); 
    }, 

    toObject: function() { 
     return fabric.util.object.extend(this.callSuper('toObject'), { name: this.name }); 
    }, 

    _render: function (ctx) { 
     this.callSuper('_render', ctx); 
    }}); 

そしてfromObject

fabric.NamedImage.fromObject = function (object, callback) { 
     fabric.util.loadImage(object.src, function (img) { 
      var instance = new fabric.NamedImage(img, object); 
      callback && callback(instance); 
     }); 
    }; 
    fabric.NamedImage.async = true; 

しかし、私は、私はここでエラー

cannot read property 'async' of undefined 

を得続けるいくつかの理由のためにキャンバスloadFromJSONをロードしようとしている私がロードしようとしているコードです。 JSON

for (i = 0; i <= canvas.length; i++) { 
        JSON.parse(imageQuery[i]); 
       canvas[i].loadFromJSON(imageQuery[i]); 
         canvas[i].renderAll(); 
         console.log(' this is a callback. invoked when canvas is loaded!xxx ');    
      } 

私はすでに cannot read property 'async' of undifinedsave canvas to server with custom attribute

名前でオブジェクトを取得するためのいくつかの方法がありますが読みましたか?

答えて

0

Plesaeは、あなたのクラスのtypeプロパティを 'namedImage'に変更します。

+0

同じエラーではまだ動作しません。私は 'nameimage'を 'namedImage'に変更しました – InnokentyDM

関連する問題