layer.find获胜't通过id返回kinetijs对象,尽管它存在

layer.find won't return a kineticjs object by id although it exists

本文关键字:对象 kinetijs 存在 返回 id 获胜 find 通过 layer      更新时间:2023-09-26

我有以下问题:我创建了两个不同的customObjects,其中包括一些kineticjs对象。在每一个上面我都有一些Kinetijs线条。行的id在自定义对象内部是不同的,但可能是两个不同mycustom对象之间的id。意思是

 mycustomobj1 hass lines with id1, id2, id3, id4
 mycustomobj2 has also lines with id1, id2, id3, id4

每条线都放在一个组中,层上的组比如lineGroup和basicLayer一个线组中有许多线路

我在mycustomoj1 上执行以下操作

mycustomobj1.lineGroup.getChildren()

并将该组中的所有行返回给我。其中一个与id1一致。但当我做时

mycstomobj1.basicLayer.find("#id1");

我得到一个空数组。

可能出了什么问题?

以及示例代码。我已经从我的obect(lineGroup)中提取了行

lines.getChildren()[11]
Kinetic.Line 
    {nodeType: "Shape", 
    _fillFunc: function, 
    _strokeFunc: function, 
    _fillFuncHit: function, 
    _strokeFuncHit: function…}
    _cache: Object
    _fillFunc: function a(a){a.fill()}
    _fillFuncHit: function c(a){a.fill()}
    _filterUpToDate: 
    false_id: 47
    _strokeFunc: function b(a){a.stroke()}
    _strokeFuncHit: function d(a){a.stroke()}
    attrs: Object
        id: "red0"
        points: Array[48]
        sceneFunc: function (a){var b,c,d,e=this.getPoints(),f=e.length,g=this.getTension(),h=this.getClosed();if(a.beginPath(),a.moveTo(e[0],e[1]),0!==g&&f>4){for(b=this.getTensionPoints(),c=b.length,d=h?0:4,h||a.quadraticCurveTo(b[0],b[1],b[2],b[3]);c-2>d;)a.bezierCurveTo(b[d++],b[d++],b[d++],b[d++],b[d++],b[d++]);h||a.quadraticCurveTo(b[c-2],b[c-1],e[f-2],e[f-1])}else for(d=2;f>d;d+=2)a.lineTo(e[d],e[d+1]);h?(a.closePath(),a.fillStrokeShape(this)):a.strokeShape(this)}stroke: "red"strokeWidth: 2
    __proto__: Object
    className:"Line"
    colorKey: "#372306"
    eventListeners: Object
    index: 11
    nodeType: "Shape"
    parent: Kinetic.Group__proto__: Object
lines.find("#red0")
[]

编辑:在将id更改为在它们之间和对象之间唯一后,它起了作用,但我认为这不是正确的行为。

Node的每个id必须是唯一的。尝试使用deffirent id。这是由KineticJS设计的。如果不需要唯一值,则可以使用name属性。