问题
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:
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.
来源:https://stackoverflow.com/questions/3817310/using-setattribute-with-an-array-of-raphael-paths