View Full Version : dynamic creation of views
melcon
09-22-2004, 06:53 PM
I'm new to Laszlo, and wondering how to dynamically create objects (views) in Laszlo (a la NEW in Java). So if you want to have a number of views that you create on the fly as they're needed, rather than just through VIEW tags on the CANVAS, for instance, how would you do it? And then how would you attach them as subviews of a certain VIEW (with the addSubview call?) Thanks for any help anybody can provide.
antun
09-23-2004, 09:52 AM
See here:
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=920&highlight=new+lzview
I wouldn't build your whole app that way because instantiative code isn't very maintainable, but it's a useful feature.
You can also use states to control the creation of views.
-Antun
melcon
09-23-2004, 11:55 AM
Great! Thank you. Now how would I do it if I want to create an instantiation of a specific class that I've created, rather than create a generic VIEW?
This might be an overkill for your task, but I've just got PHP / LZX co-working to dynamically generate lzx script "on the fly" .. see neighbouring thread here ..http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&postid=3983#post3983
I share your interest in learning how this can be done in native Laszlo rather than using external scripting.
The hello.jsp.lzx demo seems to be a similar approach.
antun
09-23-2004, 12:12 PM
The same way:
<class name="foo" />
...
var instancePointer = new foo();
-Antun
Originally posted by melcon
Great! Thank you. Now how would I do it if I want to create an instantiation of a specific class that I've created, rather than create a generic VIEW?
melcon
09-23-2004, 02:41 PM
Great! Thank you. Now how would I do it if I want to create an instantiation of a specific class that I've created, rather than create a generic VIEW?
melcon
09-23-2004, 02:44 PM
sorry, I backed up in the browser and it reposted my reply. That answer's great. Thanks all.
dionatan
10-04-2005, 05:58 PM
How can I dynamically specify the class name?? I saw at basegrid.lzx the following code:
<attribute name="_rowclass" value="basegridrow" when="once"/>
var r = new _rowclass ( content.rowparent , initArgs, cells , true );
But when I try something like this, the I get an error in debug:
tags/plcforms.lzx:28:call to non-function 'formid' (type 'string')
The code:
<method name="ativaForm" args="formname">
var formAtivar = new formname (this, {id:formname}, null, true);
</method>
Something wrong?!
antun
10-05-2005, 06:16 AM
You should be able to paramaterize the name of a class by using the global array:
var classname = "basegridrow";
new global[basegridrow]();
Taek care,
Antun
Shelby
10-05-2005, 07:08 AM
Here is a function that I created in order to create classes from a string. It also verifies that the class extends another class before instantiating it.
<!-- This method accepts a class name as an argument and attempts to instantiate it,
returning a reference to the object created -->
<method args="className, parentObj" name="_createClass"><![CDATA[
//get a Class constructor from the string
var template_class = eval(className);
//Initialize the object reference variable
var template_ref = null;
//Verify the class is a subclass of another class
if ( template_class.prototype instanceof base_class ) {
template_ref = new template_class(parentObj);
}
return template_ref;
]]>
</method>
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.