
我们可以通过创建fabric.Polygon的实例来创建一个Polygon对象。多边形对象的特征可以是由一组连接的直线段组成的任何闭合形状。由于它是 FabricJS 的基本元素之一,我们还可以通过应用角度、不透明度等属性轻松自定义它。我们可以使用 toDatalessObject 方法返回多边形的无数据对象表示。此方法返回多边形实例的对象表示。
语法
toDatalessObject( propertiesToInclude: Array ): Object
参数
propertiesToInclude(可选) - 此参数接受一个 Array,它允许我们添加要包含在输出中的任何属性。该参数是可选的。
示例1:使用toDatalessObject方法
让我们看一个代码示例,了解如何使用 toDatalessObject 方法在控制台中查看 Polygon 对象的无数据对象表示形式。
Using toDatalessObject method
You can open console from dev tools and see that the logged output contains the dataless object representation of the polygon instance
示例 2:使用 toDatalessObject 方法添加其他属性
让我们看一个代码示例,了解如何使用 toDatalessObject 方法包含其他属性。在本例中,我们添加了一个名为“name”的自定义属性。我们可以将特定属性作为选项对象中的第二个参数传递给fabric.Polygon实例,并将相同的键传递给toDatalessObject方法。
Using toDatalessObject method to add additional properties
You can open console from dev tools and see that the logged output contains the property called name
结论
在本教程中,我们使用两个简单的示例来演示如何使用 FabricJS 返回多边形的无数据对象表示。










