【发布时间】:2016-05-18 20:59:54
【问题描述】:
我正在尝试解决网站中出现的问题。看这段代码:
var retrievedJSON = workarea["modifiedOptions"];
...
canvasEl = new fabric.Canvas("canvas_" + view[i]["id"]);
if (!jQuery.isEmptyObject(retrievedJSON))
{
for (var work in retrievedJSON)
{
canvasEl.loadFromJSON(retrievedJSON[work], function() {
canvasEl.renderAll();
canvasEl.on("object:added", mouseDown);
});
}
}
有一行我想它正在尝试加载一个 json 并将它的元素放在画布中: canvasEl.loadFromJSON(retrivedJSON[work]
正在加载的json是那个:
"{"objects":[{"type":"text","originX":"left","originY":"top","left":14.08,"top":16,"width":160.84,"height":31.2,"fill":"rgb(61, 183, 228)","stroke":"rgb(0, 0, 0)","strokeWidth":0.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":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","text":"rascunho4","fontSize":"24","fontWeight":"normal","fontFamily":"MetalMacabre","fontStyle":"","lineHeight":1.3,"textDecoration":"","textAlign":"center","path":null,"textBackgroundColor":"","useNative":true},{"type":"image","originX":"left","originY":"top","left":14.08,"top":17,"width":200,"height":200,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":0.76,"scaleY":0.76,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","globalCompositeOperation":"source-over","src":"http://mydomain.com.br/tool/media/image/1454337092.png","filters":[{"type":"Resize"}],"crossOrigin":"","alignX":"none","alignY":"none","meetOrSlice":"meet"}],"background":""}"
如您所见,有一个文本和一个图像,但只有文本被加载到画布上。图像不会出现在屏幕上的画布中。为什么会这样?任何想法?你认为我的 json 可能有问题吗?
感谢任何帮助。
谢谢。
【问题讨论】: