现在我正在修改组并迭代组中的每个对象以更改数据库中的位置:
canvas.on('object:modified', (e) => {
console.log('object modified', e)
const target = e.target
const activeGroup = this.canvas.getActiveGroup()
if (activeGroup) { // Group has been modified
activeGroup.forEachObject((obj) => {
this.updateObject(obj)
})
} else {
this.updateObject(target)
}
})
updateObject = (fabricObject) => {
if (fabricObject.id) {
const obj = fabricObject.toObject()
console.log(obj)
update.call([fabricObject.id, {
$set: obj
}])
}
}
但是活动组中的实际对象不会更改坐标,只会更改组。有没有更好的方法来实施组修改?或许更好的问题是,可以反对:修改组时,为各个对象触发修改?干杯
答案 0 :(得分:0)
我建议您在有活动选择时使用与canvas导出相同的方法:
canvas.on('object:modified', (e) => {
const target = e.target
const activeGroup = this.canvas.getActiveGroup()
if (activeGroup) { // Group has been modified
activeGroup.forEachObject((obj) => {
this.updateObject(canvas._toObject(obj, 'toObject', ['id']))
})
} else {
this.updateObject(target.toObject(['id']))
}
})
updateObject = (fabricObject) => {
if (fabricObject.id) {
update.call([fabricObject.id, {
$set: fabricObject
}])
}
}