bjaspan
11-14-2005, 07:20 PM
I want to use the JavaScript eval function to evaluate expressions I get as strings from XML (specifically, my XML needs to refer to objects within my program that it operates on, and while could write code to explicitly translate from the strings to objects, I'd rather not).
It *almost* works, but not completely. In the "evals" dataset below, all the expressions evaluate correctly except the last two. I think both of the last two expressions should evaluate to the LzView containing Monday, but they evaluate to null instead. Why? Does eval not support [] or function calls?
Thanks,
Barry
<canvas>
<dataset name="days">
<day d="Mon"/>
<day d="Tue"/>
<day d="Wed"/>
<day d="Thu"/>
<day d="Fri"/>
<day d="Sat"/>
<day d="Sun"/>
</dataset>
<dataset name="evals">
<eval e="canvas"/>
<eval e="canvas.datasets"/>
<eval e="canvas.datasets.days"/>
<eval e="canvas.one"/>
<eval e="canvas.one.two"/>
<eval e="canvas.one.two.clones"/>
<eval e="canvas.one.two.clones[0]"/>
<eval e="canvas.one.two.getCloneNumber(0)"/>
</dataset>
<view name="one">
<simplelayout axis="y"/>
<view name="two" datapath="days:/day">
<text name="three" datapath="@d"/>
</view>
</view>
<view datapath="evals:/eval">
<view datapath="@e">
<method event="ondata">
<![CDATA[
Debug.write(this.data + " = " + eval(this.data));
]]>
</method>
</view>
</view>
</canvas>
It *almost* works, but not completely. In the "evals" dataset below, all the expressions evaluate correctly except the last two. I think both of the last two expressions should evaluate to the LzView containing Monday, but they evaluate to null instead. Why? Does eval not support [] or function calls?
Thanks,
Barry
<canvas>
<dataset name="days">
<day d="Mon"/>
<day d="Tue"/>
<day d="Wed"/>
<day d="Thu"/>
<day d="Fri"/>
<day d="Sat"/>
<day d="Sun"/>
</dataset>
<dataset name="evals">
<eval e="canvas"/>
<eval e="canvas.datasets"/>
<eval e="canvas.datasets.days"/>
<eval e="canvas.one"/>
<eval e="canvas.one.two"/>
<eval e="canvas.one.two.clones"/>
<eval e="canvas.one.two.clones[0]"/>
<eval e="canvas.one.two.getCloneNumber(0)"/>
</dataset>
<view name="one">
<simplelayout axis="y"/>
<view name="two" datapath="days:/day">
<text name="three" datapath="@d"/>
</view>
</view>
<view datapath="evals:/eval">
<view datapath="@e">
<method event="ondata">
<![CDATA[
Debug.write(this.data + " = " + eval(this.data));
]]>
</method>
</view>
</view>
</canvas>