如何为每个对象添加属性

如何为每个对象添加属性

本文介绍了FabricJs-如何为每个对象添加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为现有对象属性集引入一些其他属性.

I need to introduce few additional properties to existing object properties set.

喜欢:

  1. ID
  2. 地理位置>

每当我绘制形状时,都需要向该形状添加其他属性,并且需要从toDataLessJSON()

Whenever I draw a shape, I need to add additional properties to the shape and need to get from toDataLessJSON()

推荐答案

从1.7.0版开始,levon的代码停止工作.您所需要做的就是修复如下:

As of version 1.7.0 levon's code stopped working. All you need to do is to fix as follows:

// Save additional attributes in Serialization
fabric.Object.prototype.toObject = (function (toObject) {
    return function (properties) {
        return fabric.util.object.extend(toObject.call(this, properties), {
            textID: this.textID
        });
    };
})(fabric.Object.prototype.toObject);

您必须接收properties参数并将其传递给toObject.

You have to receive properties argument and pass it on to toObject.

这篇关于FabricJs-如何为每个对象添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:06