PDA

View Full Version : Use of LzReplicationManager


sandman
02-06-2003, 08:36 PM
Is there some sample code that uses the LzReplicationManager. Specifically, the xpath I have returns multiple matches. I want to run through these
matches and set attributes on the view like color, opacity to be different for different matches.

antun
02-06-2003, 09:44 PM
Hey sandman


<canvas debug="true">
<dataset name="colors">
<stripes>
<stripe name="stripe1" col="0x0000ff" />
<stripe name="stripe2" col="0xff0000" />
<stripe name="stripe3" col="0xffddee" />
<stripe name="stripe4" col="0x00ff00" />
</stripes>
</dataset>

<view id="spectrum" datapath="colors:/stripes">
<simplelayout spacing="2" />
<view name="stripes" datapath="stripe" width="50" height="50"
ondata="this.setCol( this.datapath.getNodeAttribute('col') )">
<method name="setCol" args="bgc">
this.setBGColor ( parseInt( bgc ) );
</method>
</view>
</view>

<button x="250" y="200">
<method event="onclick">
// change the color of the 3rd replicated view
// it's 0 based
myObj = spectrum.stripes.getCloneNumber ( 2 );
myObj.setAttribute( 'bgcolor', 0xff0000 );
</method>
</button>
</canvas>


Does this help?

Antun

sandman
02-12-2003, 12:42 PM
Antun,

Thanks for the sample code. I am trying to change the color of some text that I display in my app. When I
use the following code the color does not take effect

<text width="100" datapath="name[1]/text()" color="#ff0000" />

On the other hand if I use a font with some static text it works but the problem is how do I use a font with a datapath. Can you send me some sample code.

thanks,
Sandeep

antun
02-12-2003, 01:03 PM
Originally posted by sandman
Antun,

On the other hand if I use a font with some static text it works but the problem is how do I use a font with a datapath. Can you send me some sample code.

thanks,
Sandeep

I'm confused as to why this should work. 'color' is not a valid attribute of the <text> tag (http://www.laszlosystems.com/developers/learn/documentation/lzxref/LzText.php#tag), and it doesn't inherit a 'color' attribute from view either.

If you use the fgcolor attribute:

<text fgcolor="#ff0000">Smelly!</text>

You'll get red text. On the other hand if you did:

<text><font color="#ff0000">Smelly!</font></text>

You'll get red text too, but this won't work with datapaths, because the view gets replicated, and the entire contents of the <text> tag get replaced with the new text. That means that the <font> tag will get replaced too. (See here for more info: http://www.laszlosystems.com/developers/learn/documentation/tutorials/text.php#changing).

So you have two ways to solve the problem:-

a) Use the fgcolor attribute (quick & easy)
b) Give the <text> tag a method to reset it's color when data is added to it. This would be something like:


<text ondata="this.setColor( 0xff0000 )" datapath="myData:/myRoot/name/text()">Text will go here</text>


The second method is good for when things get more complicated. e.g. you may want the rows to alternate color based on some value of the data.

Take care,

Antun