如何从Farbic.js获取特定对象并读取类型

How to get a specific object from Farbic.js and read the type

如何从 Fabric.js 中获取特定对象,并确定您得到的是哪一个?就像调用 canvas.getSelectedObject() 然后确定 返回的对象是 ITextCircle 或其他对象。

谢谢。

我想instanceof可能就是你想要的。

var c = new fabric.Circle()
console.log(c instanceof fabric.Circle) // true

我相信您要找的是对象 type 属性。你可以这样使用它:

var obj = canvas.getActiveObject();
switch(obj.type) {
   case "circle":
   //stuff to do if selection is a circle
   
   break;
   case "itext":
   //stuff to do if selection is a itext
   
   break;
}