PDA

View Full Version : passing datapath dynamically to another view


felasfa
07-08-2003, 07:56 PM
I am trying to set the datapath of a view dynamically on user input

In this example, what I want to happen is the second window to reflect the user choice in the first one.

I don't want to just pass the selected text since I want later to be able to traverse the dataset in the second window.

So..

How do I find out the xpath of the view instance in the first window ? It appears the replication manager takes over the views and I'm not sure how to obtain the current xpath.

Also, how do I fire the "data" event in the second window to let it know that it's dataset has been changed and it needs to update its view ?

any help would be appreciated.


canvas debug="true" height="800" width="800">
<debug height="200" width="600" x="50" y="450"/>
<dataset name="fruits">
<fruit>Oranges</fruit>
<fruit>Apples</fruit>
<fruit>Bananas</fruit>
<fruit>Grapes</fruit>
<fruit>Kiwis</fruit>
<fruit>Papayas</fruit>
<fruit>Watermelon</fruit>
<fruit>Strawberries</fruit>
<fruit>Cherries</fruit>
</dataset>
<simplelayout axis="x"/>

<window x="50" y="50" width="100" height="300">
<view bgcolor="0xffff00" width="this.immediateparent.width" height="this.immediateparent.height">
<simplelayout axis="y" spacing="10"/>
<view onclick="send_datapath()" datapath="fruits:/fruit" clickable="true" bgcolor="0xffffff">
<text datapath="text()" resizable="true"/>
<method name="send_datapath">
<![CDATA[
debug.write("this.datapath= "+this.datapath);
two.datapath= this.datapath;
]]>
</method>
</view>
</view>
</window>

<window id="two" x="150" y="50" width="100" height="300">
<view id="two">
<text>selected fruit is:</text>
<text datapath="text()" resizable="true"/>
</view>
</window>



</canvas>

antun
07-09-2003, 04:52 PM
OK, this is a bit hacky:


<canvas debug="true" height="800" width="800">
<debug height="200" width="600" x="50" y="450"/>
<dataset name="fruits">
<fruit>Oranges</fruit>
<fruit>Apples</fruit>
<fruit>Bananas</fruit>
<fruit>Grapes</fruit>
<fruit>Kiwis</fruit>
<fruit>Papayas</fruit>
<fruit>Watermelon</fruit>
<fruit>Strawberries</fruit>
<fruit>Cherries</fruit>
</dataset>
<simplelayout axis="x"/>

<window x="50" y="50" width="100" height="300">
<view bgcolor="0xffff00" width="this.immediateparent.width"
height="this.immediateparent.height">
<<attribute name="myDP" type="string" value="fruits:/fruit" />
method event="oninit">
this.allFruits.setDatapath( this.myDP );
</method>
<simplelayout axis="y" spacing="10"/>
<view name="allFruits" onclick="send_datapath()"
datapath="" clickable="true" bgcolor="0xffffff">
<text datapath="text()" resizable="true"/>
<method name="send_datapath">
<![CDATA[
var dp = parent.myDP + '['
+ this.datapath.getNodeOffset() + ']';
two.setDatapath( dp );
]]>
</method>
</view>
</view>
</window>

<window id="two" x="150" y="50" width="100" height="300">
<view id="two">
<simplelayout axis="y" spacing="10"/>
<text>selected fruit is:</text>
<text datapath="text()" resizable="true"/>
</view>
</window>
</canvas>


Right now there isn't a way to get the string datapath of a replicated view or a LzReplicationManager (although I have filed a feature request for this). So what I did was to record the value and set it when the parent view inits. Then I can access it from the send_datapath() method, and append "[1], [2], [3], [n] etc.", where n is the clone number (accessible using getNodeOffset()).

That's the hacky part out of the way.


Also, how do I fire the "data" event in the second window to let it know that it's dataset has been changed and it needs to update its view ?


Here's the problem - you said:


two.datapath= this.datapath;


... that's not going to fire the ondata event. You have to use setDatapath() to do that. The same goes for any other attribute: x, y, width etc. You can set an attribute just by assigning it a value:


this.foo = 'bar';


... but that won't send an event. You have to say:


this.setAttribute( 'foo', 'bar' );


... or for predefined attributes (x,y,width,datapath etc.) you can say setX(), setY(), setDatapath(), etc.

Take care,

Antun

felasfa
07-10-2003, 05:39 AM
aha !

I knew it would have something to do with nodeOffset and LzReplicationManager but couldn't figure it out.

Agree with the requested feature - seems like a node should know what it is to be useful.

thanks a lot.

f