2017-02-17 38 views
2

我無法調整這些項目的大小。 set函數不起作用,不識別對象集合。我需要調整面料js中的選定項目

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}); 
+0

我的回答對你有幫助嗎?你還需要什麼嗎? –

回答

1

這是一個可用的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功能不工作的對象是不確定的,你有沒有主動「羣」 - 你只有與活動屬性設置爲true的對象。