KineticJS icon indicating copy to clipboard operation
KineticJS copied to clipboard

Shape.name supports spaces but Layer.get(.<name>) does not

Open Verron opened this issue 13 years ago • 3 comments

If a shape has a space within its name, it can not be pulled via the layer's get function.

Workaround: Use the shape's ID instead of its name when using Layer.get. Ex: kLayer.get('#22')

Verron avatar Aug 01 '13 18:08 Verron

Also, it seems shape._id can be different from shape.attrs.id. Is shape._id unique? if it is, Layer.get would be awesome if you can search via this _id property.

Verron avatar Aug 01 '13 18:08 Verron

Shape.get('#25')[0] Group.get('#20')[0] Layer.get('#22')[0] Stage.get('#21')[0] // only single (unique)

var shapeObjects = Layer.get('Shape'); // get objects in Type var shapeObject = shapeObjects.toArray()[0]; // get first object

ConTrast77 avatar Aug 29 '13 00:08 ConTrast77

node.id is a Kinetic generated id for each node that shouldn't really be useful for you. Also, you should not use spaces for names and ids (think CSS selectors). you can use "-" or ""

ericdrowell avatar Nov 03 '13 06:11 ericdrowell