PDA

View Full Version : getValue returning two seperate values.


jakeh
08-25-2004, 10:18 AM
I have a list that is populated with data from an XML file. I am running in debug mode and it is returning two values when I select an item (note: it only returns 1 value for the first item selected, after that it returns the former items value and the new items value). Also, it returns it this way wheter i choose to use an onSelect method or onSelected.


Code:

::datalistbox.lzx::

<canvas debug="true">
<dataset name="contactdata" src="contacts.xml" />
<class name="datalistbox" extends="list" width="200" shownitems="5">
<textlistitem datapath="${classroot.path}">
<method event="onSelected">
debug.Write(this.getValue());
</method>
<method event="onData">
var mytxtpath = classroot.txt + "/text()";
var mytxt = this.datapath.xpathQuery( mytxtpath );
this.setAttribute( "text" , mytxt );
var myvalpath = classroot.txt + "/text()";
var myval = this.datapath.xpathQuery( myvalpath );
this.setAttribute( "text" , myval );
</method>
</textlistitem>
</class>
<datalistbox txt="fullname" val="id" path="contactdata:/phonebook/contact/" />
</canvas>


::contacts.xml::

<phonebook>
<contact>
<id>001</id>
<fullname>John A Smith</fullname>
</contact>
<contact>
<id>002</id>
<fullname>John S Smith</fullname>
</contact>
<contact>
<id>003</id>
<fullname>John M Smith</fullname>
</contact>
<contact>
<id>004</id>
<fullname>John R Smith</fullname>
</contact>
<contact>
<id>005</id>
<fullname>John J Smith</fullname>
</contact>
</phonebook>


Thanks for any help with this.

Jake

jdfreedman
03-10-2005, 07:01 AM
Jake,

I'm having the same problem, but found a very simple workaround. It appears that the onselect and onselected events are getting triggered when an item gets unselected as well as when it is selected. So ...

<method event="onselect">
if (this.selected) {
debug.write("in onselect");
}
</method>

The "if" only allows the code to execute if the item is really "selected".

Jeff