View Full Version : xpath = null
kampfkolosso
02-09-2008, 09:23 AM
Hello All!
It's xpath again :mad: !
How do i get the xpath of a list item selected in my list?
I've a setup like this:
<canvas debug="true">
<dataset name="mydata">
<list dataoption="lazy" name="thelist">
<textlistitem datapath="mydata:/path/to/data"/>
</list>
<button text="test me">
<handler name="onclick">
Debug.write(canvas.thelist.getSelection().xpath);
</handler>
</button>
</canvas>
Elements, etc. showing up nicely, getSelection() delivers the expected datapointer, but xpath attribute is null?
#1 How come?
#2 How to get xpath string?
many thx for every help!
frethog
02-13-2008, 09:47 AM
Although I can guess why you'd want the xpath for a selected item, here's how you can get a single LzDataElement for the selected item. You iterate through the replication managers clones until you find a clone having the selected value of true, then you access it's data attribute.
From there you should be able to use LzDataNode and LzNode methods (and those of their subclasses) to manipulate the data element to a point where you get the information you're seeking (if it's truly the xpath, which I don't believe is set by default for a datapointer).
<canvas debug="true">
<dataset name="mydata">
<list dataoption="lazy" name="thelist">
<textlistitem id="mylistitems" datapath="mydata:/path/to/data"/>
</list>
<button text="test me">
<handler name="onclick">
//Debug.write(canvas.thelist.getSelection().xpath);
var the_text = false;
var i_counter=0;
while(!mylistitems.clones[i_counter].selected){
i_counter++;
}
var myLzDataElement = mylistitems.clones[i_counter].data;
</handler>
</button>
</canvas>
rcyeager
02-13-2008, 10:21 AM
frethog's code to get the LzDataElement for the selected list item is ill-advised. All you have to do is "canvas.thelist.getSelection().p" to get the LzDataElement being pointed to by the LzDatapointer.
As far as getting the xpath to the selected node, the replicator doesn't seem to store the parsed path, so it looks like you would have to write an algorithm to determine the node's placement in the XML schema. Going up the path is easy using getParent() until you reach the top, but then you'll have to find the offset of the selected child within the immediate parent's set of children to arrive at an xpath like "mydata:/item[4]/text()". Another scenario is when the value of the node is really an attribute value, which leads to a different xpath result like "mydata:/item[4]/@valueAttr".
Robert
http://www.qrowd.com
http://www.cooqy.com
kampfkolosso
02-13-2008, 10:27 AM
Erhh, sorry frethog, but that's a bit complicated for achieving the same thing in one line:
var myLzDataElement = canvas.thelist.getSelection().data;
I needed the xpath to set the xpath of a form. To have the data selected via the list displayed in the form. I have done something like the following:
<canvas debug="true">
<dataset name="mydata">
<class name="mylistitem" extends="listitem" layout="axis:x; class:resizelayout">
<text datapath="@id" width="30"/>
<text datapath="name/text()" width="30" options="releasetolayout"/>
<handler name="onclick">
canvas.mydialog.setDatapath("mydata:/path/to/data[@id = '"+this.datapath.getNodeAttribute("id")+"']");
canvas.mydialog.open();
</handler>
</class>
<list dataoption="lazy" name="thelist">
<mylistitem datapath="mydata:/path/to/data"/>
</list>
<modaldialog name="mydialog"...>
<text datapath="@id" resize="true"/>
...
</modaldialog>
</canvas>
But inserting an id is not always possible and so it would have been nice to simply get the xpath of the selected object:D
regards
frethog
02-13-2008, 10:57 AM
Kudos. Peace. :o
rcyeager
02-13-2008, 12:06 PM
Maybe this will get you closer:
<canvas debug="true">
<dataset name="mydata">
<item value="item1" >item one</item>
<item value="item2" >item two</item>
<item value="item3" >item three</item>
<item value="item4" >item four</item>
<item value="item5" >item five</item>
<item value="item6" >item six</item>
</dataset>
<list dataoption="lazy" name="thelist" shownitems="6">
<textlistitem datapath="mydata:/item" text='$path{"text()"}' value='$path{"@value"}' onclick="Debug.write(this.datapath.xpath+'['+(this.clonenumber+1)+']')"/>
</list>
</canvas>
See the onclick code I added to the textlistitem...it seems to correctly write out the xpath to the bound node that is clicked.
Robert
http://www.qrowd.com
http://www.cooqy.com
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.