View Full Version : updating datapath
ch_bowen
07-15-2003, 09:10 AM
I was wondering how to add a node to a datapath and more specifically, adding a node with attributes or modifying a node with attributes. Would someone be able to show me how this is done?
Thank you.
antun
07-15-2003, 09:25 AM
Here's one way, that uses a datapointer, which is like a cursor that points to a place in a dataset:
<canvas debug="true">
<dataset name="myDS">
<myrootnode />
</dataset>
<button>
<method event="onclick">
var dp = myDS.getPointer().getXPath('myrootnode');
dp.addNode( 'mynewnode', 'Lorem Ipsum', {'foo':'bar'} );
debug.write( dp.serialize() );
</method>
</button>
</canvas>
First we get a pointer by calling the getPointer() method of the dataset. There's other ways to do this -yyou could have declared a pointer using the <datapointer> tag too. See the datapointer docs for more:
http://www.laszlosystems.com/developers/learn/documentation/lzxref/datapointer.php
Then we move that pointer to where we want to add a node (by calling the getXPath() method). Here we get it to the root node.
Finally we add a child node to where the pointer is pointing using the addNode() method.
Does that answer your question?
-Antun
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.