PDA

View Full Version : Type-casting from LzDataNode to LzDataText. How?


tiziano.fagni
10-02-2005, 03:22 AM
Hi,
sorry for the stupid question but I am new to Laszlo developing...
Suppose I have a method like this:

<method name="test" args="ds">
var el = ds.getElementsByTagName("idActor");
var elem = el[0];
var elem2 = (LzDataText) elem;
var idActor = elem2.data;

.....
</method>

The input variable "ds" is a record inside a dataset that is an instance of LzDataNode object (in particular I think of LzDataElement class)
The compiler give me an error in the type-casting expression (a la Java). Evidently is a Javascript syntax error but, knowing that an object (elem) is of type LzDataText and returned by .getElementsByTagName() method as LzDataNode object, how I can convert it to LzDataText?

Thanks for your help.
Tiziano

tiziano.fagni
10-03-2005, 04:37 AM
Someone can help me, please? Thanks...

bfagan
10-03-2005, 05:52 AM
Perhaps you want:


var el = ds.getElementsByTagName("idActor").getFirstChild();

tiziano.fagni
10-03-2005, 06:12 AM
Originally posted by bfagan
Perhaps you want:


var el = ds.getElementsByTagName("idActor").getFirstChild();


No, I don't want this. Maybe it's more clear for you if I post the XML tag printed by debugger.
The variable "ds" prints this:

<100>
<indirizzo>Ind100</indirizzo>
<ragSociale>RagSociale100</ragSociale>
<idAttore>100</idAttore>
</100>

and the the variable "el" prints this:

<idAttore>100</idAttore>

I want to extract the value 100 from the variable "el". This variable is of generic type LzDataNode but it's real type must be LzDatatext. Knowing this, How can I convert the object "el" into a LzDatatext?

bfagan
10-03-2005, 06:31 AM
getFirstChild on an lzDataElement should return the lzDataText value:



<canvas width="900" height="300" debug="true">


<dataset name="foobar">
<t100>
<indirizzo>Ind100</indirizzo>
<ragSociale>RagSociale100</ragSociale>
<idAttore>100</idAttore>
</t100>
</dataset>

<button text="hit me">
<method event="onclick">
debug.write(foobar.getPointer().xpathquery('/t100/idAttore').getFirstChild());
</method>
</button>
</canvas>

tiziano.fagni
10-03-2005, 06:45 AM
Originally posted by bfagan
getFirstChild on an lzDataElement should return the lzDataText value:



<canvas width="900" height="300" debug="true">


<dataset name="foobar">
<t100>
<indirizzo>Ind100</indirizzo>
<ragSociale>RagSociale100</ragSociale>
<idAttore>100</idAttore>
</t100>
</dataset>

<button text="hit me">
<method event="onclick">
debug.write(foobar.getPointer().xpathquery('/t100/idAttore').getFirstChild());
</method>
</button>
</canvas>


Ok, it works, thank you for your help!