Using setAttribute with an array of Raphael paths

2019-09-02 18:24发布

When 'things' in the following code is an array of paths...

things.square = [ RM.path("m 154.21525,71.431259 74.32805,0 0,70.496711 -74.32805,0 0,-70.496711 z").attr(attr),
                  RM.path("m 271.25132,77.933263 58.07304,0 0,56.409037 -58.07304,0 0,-56.409037 z").attr(attr2)   ];

...then this code does not work:

    things.square[1].node.setAttribute("id","clicker");

ie it fails to assign the second path in the array to id 'clicker'. However, when 'things' is just a single path...

things.square = RM.path("m 154.21525,71.431259 74.32805,0 0,70.496711 -74.32805,0 0,-70.496711 z").attr(attr);

...then it works fine:

things.square.node.setAttribute("id","clicker");

Why is this? And how can I get the first array of paths case to work? Thanks!

1条回答
爷、活的狠高调
2楼-- · 2019-09-02 18:59

I don't quite understand the purpose of the code but I would check if attr2 is valid - that's the only significant thing that the two paths differ in.
Also posting the error message and what objects are null when the exception occurs would be nice.

查看更多
登录 后发表回答