转换为JSON时出现问题

时间:2015-09-25 13:46:13

标签: javascript json canvas fabricjs

大家。我使用Fabric.js开发项目,转换为JSON时发现了一个问题

我裁剪一个物体。对于裁剪,我使用函数:

 activeObject.clipTo = function(ctx) {
    ctx.beginPath();
    ctx.fillStyle="#A2322E";
    ctx.moveTo(-leftPointCropShape, -topPointCropShape+storonaX);
    ctx.lineTo(leftPointCropShape,-topPointCropShape);
    ctx.lineTo(leftPointCropShape,topPointCropShape);
    ctx.lineTo(-leftPointCropShape,topPointCropShape);
    ctx.closePath();
    ctx.fill();
};`

JSON.stringify(canvas.toDatalessJSON());之后我有下一个字符串:

> {"objects":[{"type":"image","originX":"left","originY":"top","left":254,"top":44,"width":88,"height":144,"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,
"clipTo":"function(ctx)
{\r\n\t\tctx.beginPath();\r\n\t//ctx.fillStyle=\"#A2322E\";
\r\n\tctx.moveTo(-leftPointCropShape,-topPointCropShape+storonaX);
\r\n\tctx.lineTo(leftPointCropShape,-topPointCropShape);
\r\n\tctx.lineTo(leftPointCropShape,topPointCropShape);
\r\n\tctx.lineTo(-leftPointCropShape,topPointCropShape);
\r\n\tctx.closePath();\r\n\t//ctx.fill();\r\n\t}",
"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"multiply","src":"http://localhost/test20/image/elements/shtora/3.png","filters":[],"crossOrigin":"","alignX":"none","alignY":"none","meetOrSlice":"meet"}],"background":"#F5F5F5"}
>

问题是JSON中有变量名称而不是它们的值。

ctx.lineTo(leftPointCropShape,-topPointCropShape);

是Fabric的错误吗?

如何在JSON中插入值而不是变量'names“leftPointCropShape”,“topPointCropShape”?

0 个答案:

没有答案