简体   繁体   English

在fabric.js 上如何获取活动对象上的项目(计数)

[英]on fabric.js how to get the item(count) on active object

How can I get the canvas.item(#) or src of active object in fabric.js.如何在fabric.js 中获取活动对象的canvas.item(#) 或src。 I have the following.我有以下内容。 but get_id() function returns "Layer_1" every time for any object但是 get_id() 函数每次对任何对象都返回“Layer_1”

 function load() {
        fabric.Object.prototype.transparentCorners = false;
        fabric.loadSVGFromURL('images/test.svg', function (objects, options) {
            var shape = fabric.util.groupSVGElements(objects, options);
            canvas.add(shape.scale(1));
            shape.set({ left: 200, top: 100, ZIndex: 10 }).setCoords();
            canvas.renderAll();
        }) ; }


  function get_id() {
        var obj = canvas.getActiveObject();
        var newCanvasId = obj.id;
        alert(newCanvasId)
}

I would like to get unique id or item(#) image name or src or .... to identify this active object.我想获得唯一的 id 或 item(#) 图像名称或 src 或 .... 以识别此活动对象。 any help please?有什么帮助吗?

Thanks after adding id to the object under set, I can get each object by thier id.感谢将 id 添加到 set 下的对象后,我可以通过他们的 id 获取每个对象。

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM