My RIA has the need to instatiate a tab for an xmldata stream,
dynamically bound.

Perhaps I've missed something in the documentation/lists, but didn't
find anything

that readily provided a basis for this need.

I wasn't able to control the timing of the databinding, causing troubles
with using
child nodes/attributes from an xml
element to instantiate the tab. The databinding
would trigger on creating the parent element, when useful data was in
the child.

This is what I came up with eventually -
1. Use a temporary dataset to create the new element completely
2. Use real_dp.addNodeFromPointer(temp_dp) to trigger databining.
3. Delete the node from the temporary dataset.

This was way too much time for something this simple.
Attached is my crude sample that seems to work - perhaps it'll be useful to
others.

Perhaps it'd be a good idea to have a cookbook section on the wiki where
things
like things like this could be stored.

Are there better ways of accomplishing this? I'd be really glad to hear
back.

-shishir

<canvas debug="true" height="50%" width="100%">

<dataset name="mydata">
<tabs>
</tabs>
</dataset>

<dataset name="temp">
<tabs>
</tabs>
</dataset>

<view height="50%" width="100%">
<button>Add to dataset
<method event="onclick">
var temp_dp = canvas.datasets.temp.getPointer();
temp_dp.setXPath('temp:/tabs');

temp_dp.addNode('tab', 'Tab 1 text', { name: 'tab' + Math.random()});
// Write out the contents of the dataset for debugging
Debug.write( temp_dp.serialize() );
var real_dp = canvas.datasets.mydata.getPointer();
real_dp.setXPath('mydata:/tabs');
temp_dp.setXPath('temp:/tabs/tab');
real_dp.addNodeFromPointer(temp_dp);
Debug.write('real_dp' + real_dp.serialize());
temp_dp.deleteNode(temp_dp);
</method>
</button>

<tabs id="definitions" y="50" width="100%" height="50%"
datapath="mydata:/tabs">

<tabpane datapath="tab" text="New Tab" >
<method event="ondata">
Debug.write('ondata invoked');
var word = datapath.xpathQuery('@name');
//var word = d;
Debug.write('ondata- setting name to - ' + word);
this.setAttribute('text', word);
</method>
</tabpane>
</tabs>
</view>
</canvas>

Reply via email to