PDA

View Full Version : Dynamically setting a view's source


thobson
09-09-2008, 03:54 PM
Hi

I hope someone can help me with this because I've been struggling with it for about a week now!

I have a remote dataset which returns data in the form:
<cliparts>
<clipart>
<id>1</id>
<width>10</width>
<height>10</height>
<src>http://localhost:8080/clipart/1.swf</src>
</clipart>
<clipart>
...
</clipart>
</cliparts>

I want to create a series of views based on this dataset, I was hoping to do something like:

<view name="container">
<view datapath="getCliparts/cliparts/clipart">
<attribute name="source" value="$path{'src/text()'}" />
<attribute name="width" value="$path{'width/text()'}" />
<attribute name="height" value="$path{'height/text()'}" />
</view>
<simplelayout axis="y" />
</view>

The problem is that the layout is completely screwed, the views appear on top of each other and the size is ignored.

I'm using OL 3.3.3

Thanks!

Toby

rcyeager
09-09-2008, 05:48 PM
Here's a working solution tested w/ 4.0.12:


<canvas>
<dataset name="ds">
<cliparts>
<clipart><id>1</id><width>100</width><height>100</height><src>http://www.google.com/intl/en_ALL/images/logo.gif</src></clipart>
<clipart><id>1</id><width>200</width><height>200</height><src>http://www.google.com/intl/en_ALL/images/logo.gif</src></clipart>
<clipart><id>1</id><width>300</width><height>300</height><src>http://www.google.com/intl/en_ALL/images/logo.gif</src></clipart>
</cliparts>
</dataset>

<view name="container" datapath="ds:/cliparts">
<simplelayout axis="y" spacing="10"/>
<view datapath="clipart" stretches="both">
<handler name="ondata">
this.setAttribute("source", this.datapath.xpathQuery("src/text()"));
this.setAttribute("width", parseInt(this.datapath.xpathQuery("width/text()")));
this.setAttribute("height", parseInt(this.datapath.xpathQuery("height/text()")));
</handler>
</view>
</view>
</canvas>


Note that the width and height must be set as integer values. I'm not sure the $path approach will do the needed conversion.

Robert Yeager
http://www.qrowd.com

thobson
09-10-2008, 04:21 AM
Thanks Robert ... that works nicely :)