View Full Version : Can we pass dataset as attribute
ankushb
06-27-2005, 06:09 AM
Hi,
Can we pass dataset as attribute as
<Tree name="tr" colordata="data1" />
thx
skorpiun
06-27-2005, 02:11 PM
I have tried and not been able to pass in a dataset as an attribute. However, it is worth noting that datasets on the canvas level are globally accessible. So the following code works fine...
<canvas width="200" height="150">
<dataset name="data1">
<colordata>
<color>red</color>
<color>green</color>
<color>blue</color>
</colordata>
</dataset>
<class name="Tree">
<basegrid datapath="data1:/colordata" width="200">
<basegridcolumn>
<text placement="header">Color List</text>
<checkbox text="$path{ 'text()'}" value="$path{'text()'}">
</checkbox>
</basegridcolumn>
<scrollbar placement="content"/>
</basegrid>
</class>
<Tree name="tr" />
</canvas>
However, this is not very good OOP because it does not allow for encapsulation of the dataset within the appropriate object (Maybe someone from LaszloSystems can give some insight into why this is and if they have any plans on changing it?). However, to get around that I have been able to create a dataset on the fly within a class’s onconstruct event...
<canvas width="200" height="150">
<class name="Tree">
<attribute name="uid" type="string"/>
<method event="onconstruct">
var p=new LzParam();
p.addValue( "param1", "value1", true);
this.setAttribute('mydata', new LzDataset(this, {name:'mydata'+uid,
type:'http',
src:'myXMLDoc.xml',
querystring:p,
request:true,
timeout:30000,
queuerequests:true}));
</method>
<basegrid datapath="$once{'mydata'+parent.uid+':/colordata'}" width="200">
<basegridcolumn>
<text placement="header">Color List</text>
<checkbox text="$path{ 'text()'}" value="$path{'text()'}">
</checkbox>
</basegridcolumn>
<scrollbar placement="content"/>
</basegrid>
</class>
<Tree name="tr" uid="someUniqueID" />
</canvas>
But this should probably be avoided if you don’t require unique dataset for each object of the class (and maybe someone else has a more elegant solution for this situation too?).
Hope that help some.
If neither of these options does not meet your needs you might need to provide more information about your specific situation.
amuntz
06-28-2005, 11:37 AM
Saw that Adam Wolff answered this in the mailing lists. Thought I'd copy his reply here for everyone to see.
Adam Wolff wrote:
Yes -- you'll need to declare the colordata attribute as when="once"
to make sure that the dataset is instantiated before the expression
is evaluated.
The more idomatic way to do this would be to use an xpath, like
this:
<class name="ColorTree">
<attribute name="colorxpath" type="string"/>
<datapointer name="pointerToColorData"
xpath="$once{ classroot.colorxpath }"/>
<ColorTree colorxpath="data1:/"
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.