loadFromJSON在加载Fabric JS后忽略自定义属性

时间:2017-08-06 06:02:41

标签: javascript fabricjs

我正在使用1.5版本,我遇到了一些奇怪的问题。 我获得了JSON,我的自定义属性被导出并保存在我的服务器端

  canvas.includeDefaultValues = false;
  var json = canvas.toJSON([ 'centeredRotation', 'selectable']);
  return JSON.stringify(json);

但是在加载画布JSON之后,自定义属性消失了,我不知道为什么 我按如下方式加载json:

function loadCanvasFromJson(canvasM){
         var jsonCanvas = $('#jsonCanvas').val();
         var jsonObject = JSON.parse(jsonCanvas);
         jsonCanvas = JSON.stringify(jsonObject);
         canvasM.loadFromJSON(jsonCanvas, canvasM.renderAll.bind(canvasM));

       setTimeout(function() {
            var objects = canvas.getObjects();
            console.log(objects);
            for (var i in objects) {

          var positions   = calcPixelsByPercentage(objects[i].percentage_left, objects[i].percentage_top, canvas);//percentages positions
          var size        = calcPixelsByPercentage(objects[i].percentage_width , objects[i].percentage_height, canvasM); //percentages size
                    /*calculating new scale objects responsive*/
                    var scale = size.left / objects[i].width;
                    objects[i].scaleX   = scale;
                    objects[i].scaleY   = scale;
                    objects[i].left     = positions.left;
                    objects[i].top      = positions.top ;
                    objects[i].setCoords();
            }
            canvasM.renderAll();
            console.log('after load Canvas');
            console.log(canvasM.toJSON([ 'centeredRotation', 'selectable']));

        }, 1000);

感谢您的帮助,我想某处有一个错误。

0 个答案:

没有答案