简体   繁体   中英

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. I have the following. but get_id() function returns "Layer_1" every time for any object

 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. any help please?

Thanks after adding id to the object under set, I can get each object by thier id.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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