PDA

View Full Version : problem with setting dynamic name


sitence
05-05-2009, 06:47 PM
I want to set the text name getting from an xml file or dataset, but I get a Compilation Warning. Can anybody give me suggestions. My code as follow.
<canvas height="500" debug="true" proxied="false">
<dataset name="mybook">
<unit>
<lesson name="s1" text="hello1"/>
<lesson name="s2" text="hello2"/>
<lesson name="s3" text="hello3"/>
</unit>
</dataset>
<view x="400" layout="axis:y">
<text datapath="mybook:/unit/lesson" name="$path{'@name'}" text="$path{'@text'}"/>
</view>
</canvas>
Compilation Warnings
lab.lzx:11:85: The name attribute of this node, "$path{'@name'}", is not a valid javascript identifier

spoco2
05-05-2009, 07:35 PM
Just remove the name portion. You shouldn't be referencing views in a replicated dataset by name anyway, they become clones and should be accessed via replication managers.

Unless there is some iron clad reason you want them to be named, remove that and it works fine.

sitence
05-06-2009, 05:00 AM
I know it works fine if remove the name portion, but if I want to access the text, what should I do. For example, I want to set the "hello2" bgcolor different. Are there any ways except calling it's name.
Could anybody give a demo according to my code? Thanks.

senshi
05-06-2009, 08:07 AM
The "name" attribute is initialize-only, so you cannot use constraints here, also see reference: lz.node#name (http://www.openlaszlo.org/lps4.3/docs/reference/lz.node.html#LzNode.__ivars__.name)