How to get Children that have same type Kineticjs?

半城伤御伤魂 提交于 2019-12-04 19:47:23

sorry for not having a tutorial on this, but you can select children by type like this:

var shapes = layer.get('Line');

in KineticJS, shape types are similar to DOM tags. You can select them by name.

So the @Grant Timmerman example will work but I'm not sure that for children you can have only shapes so here what I suggest you to do:

  var lines = G1.getChildren().filter(function(element) {
    return element instanceof Kinetic.Line;
  });

I don't know kinetic very well that's why I'm making that assumption.

Simply use the Shape's shapeType property.

Here's an example that gets an array of KineticJS Lines

var lines = G1.getChildren().filter(function(element) {
    return element.shapeType === 'Line';
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!