将 setAttribute 与 Raphael 路径数组一起使用 [英] Using setAttribute with an array of Raphael paths
问题描述
当以下代码中的事物"是路径数组时...
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");
即它无法将数组中的第二个路径分配给 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!
推荐答案
我不太明白代码的用途,但我会检查 attr2 是否有效——这是两条路径唯一不同的地方.
还发布错误消息以及发生异常时哪些对象为空会很好.
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.
这篇关于将 setAttribute 与 Raphael 路径数组一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!