[Laszlo-user] Data Manipulation Confusion

Adam Wolff adam at laszlosystems.com
Wed Apr 12 12:09:01 EDT 2006

Here's the general approach you want to take.

What you want to do is to hand your editor a LzDataElement that is cloned
from the template. Note that this node doesn't need to be part of a
dataset; you can hand an xml node directly to a datapath that you've

<class name="editor" extends="window">
    <!-- be sure to create a datapath, since we're not going to use xpath
         for databinding here -->

var newnode = template.getFirstChild().getFirstChild().cloneNode( true );

editor.datapath.setPointer( newnode );
//user fills out form

//when user clicks ok
ds1.getFirstChild().appendChild( editor.datapath.p );

Hope this helps.


On Apr 11, James Howe wrote:

> I've been working on a data related problem for the last few days which  
> really has me confused.  I must be missing something.  I'm trying to do  
> something very simple.  I have two XML datasets:
> <dataset name="ds1">
> 	<items>
> 		<item name="foo" address="bar"/>
> 	</items>
> </dataset>
> <dataset name="template">
> 	<items>
> 		<item name="" address=""/>
> 	</item>
> </dataset>
> I have a simple editor which is bound to ds1 with a datapath like this:
> datapath="ds1:/items/item"
> The user can change things in the editor and save them.  They can also  
> select 'New' to start again.  What I've been trying to figure out is how  
> to clone the item element from my template dataset and use it to replace  
> the edited value found in ds1.  Looking in the documentation I can see how  
> I could add the template item to ds1 and then delete the original node  
>  from ds1 using the addNodeFromPointer, but then if the user edits the  
> values, the values in my template are disturbed.  What I want to do is add  
> a deep clone of my template node to the ds1 dataset so that if/when it  
> gets edited, my template remains unaffected.
> What am I missing?  I can find the node I'm interested in by doing  
> xpathQueries.  I can clone the LzDataElement returned from the  
> xpathQuery.  Once I have that, I don't see how I can add that element as a  
> node in my ds1 dataset.
> Any help on this would be greatly appreciated.
> Thanks!

More information about the Laszlo-user mailing list