我无法调整这些项目的大小。 set
函数不起作用,无法识别对象集合。
canvas.loadFromJSON(json,canvas.renderAll.bind(canvas))
canvas.renderAll();
//select all items first (this works)
var objs = canvas.getObjects().map(function(o) {
return o.set('active', true);
});
//deactivate some items i dont want to resize (this works)
canvas.item(0).set('active', false);
canvas.item(1).set('active', false);
canvas.item(2).set('active', false);
canvas.item(3).set('active', false);
canvas.item(4).set('active', false);
canvas.renderAll();
//the problem starts here
var o = canvas.getActiveGroup();
o.set({width:100, height:100});
这是一个正在运行的 JSFiddle,http://jsfiddle.net/rekrah/pnpc3j3r/ .
canvas.loadFromJSON(json,canvas.renderAll.bind(canvas))
canvas.renderAll();
//select all items first (this works)
var objs = canvas.getObjects().map(function(o) {
return o.set('active', true);
});
canvas.renderAll();
//deactivate some items i dont want to resize (this works)
canvas.item(0).set('active', false);
canvas.item(1).set('active', false);
canvas.item(2).set('active', false);
canvas.item(3).set('active', false);
canvas.item(4).set('active', false);
canvas.renderAll();
//this is where the problem goes away
canvas.getObjects().map(function(o) {
return (o.active ? o.set({
width: 100,
height: 100
}).setCoords() : o);
});
canvas.renderAll();
set
函数不起作用的原因是对象未定义,您没有事件的“组” - 您只有 active 属性设置为 true 的对象。
我是一名优秀的程序员,十分优秀!