我正在尝试使用fabric.js库将属性添加到我的SVG输出中。 这是我的代码:
objectGlobal = new fabric.Rect({
// here are some Rect attributes such as height width etc
room_id: counter
});
objectGlobal.toSVG = (function(toSVG) {
return function() {
console.log("overriden to svg");
return fabric.util.object.extend(toSVG.call(this), {
room_id: this.room_id
});
};
})(objectGlobal.toSVG);
canvas.add(objectGlobal);

我得到了#s;重写svg"在我的控制台中,但我的SVG输出不包含room_id属性。 这是SVG输出:
<rect x="-93.5" y="-49.5" rx="0" ry="0" width="187" height="99" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(229,229,229); fill-rule: nonzero; opacity: 1;" transform="translate(318 160)"/>
&#13;