我正在使用fabric 3.4创建一个提供klass对象的画布元素。
比方说,我有变量a作为
a = klass {lockScalingX: true}我将其克隆到b中,并使用一些字典对象更新b
b = a.clone();
b.set({lockMovementY: true});但这带来了一个错误,
index.html:3 ERROR TypeError: Cannot read property 'set' of undefined当我控制台日志a和b时。克隆后的b是undefined。
如何克隆klass set() 对象并使用set()来更新值?
或将织物的更改为简单对象?
编辑2
下面是控制台日志的截图。

它是一个数组,控制台有8,9,10键打印。我扩展了8以显示键中包含的值。
b[s] = a[s].clone();
console.log('a: ', a); // This consoles the first code in the question.
console.log('b[s]: ', b[s]); // This prints undefined
b[s].set({lockMovementY: true}); // This is giving error. Cannot read property set of undefined.发布于 2019-11-14 05:43:04
我通过调用织物的toObject()方法来解决这个问题。
早些时候,我使用了fabric 1.x,并且正在进行一次项目改造。在将fabric升级到3.x之后,我开始面临这个问题。在创建fabric画布时,返回klass类型的对象。
const canvas = new fabric.Canvas();为了将klass转换为object,我使用了toObject()方法,如
canvas.toObject()它返回简单对象,而不是klass对象。
https://stackoverflow.com/questions/58748366
复制相似问题