On 25 January 2011 16:15, Walter Lee Davis wa...@wdstudio.com wrote:
I've done the following a lot in a piece of code I'm working on:
var t = new Template('div id=id_#{num}.../div');
$R(1,4).each(function(n){
$('page').insert(t.evaluate({num:n}));
//and then I need to add some extras to that div
//so I end up doing this to get a handle on it
$('id_' + n ).doSomethingElse();
});
Is there another way to return a reference to a new template-based element so
I don't have to do a find by ID (and worry about browsers' lag times in
recognizing new DOM objects)?
I can obviously just to this:
var newElement = new Element('div',{id:'id_' + n});
and I have done so in a few other places, but Templates are so nice and clean
and reduce the concatenation to a minimum. (Plus, this is a cut-down example
and the real thing is much more complex.) It would be nice if insert could
return an object reference to the object created, rather than the object that
you're inserting into, or if Template could refer somehow to the object
created rather than just the string that will define it once it's inserted in
another element.
Walter
Template.evaluate doesn't create an object, just a string, so there is
no way to maintain a reference to anything. Only if you insert the
string into the DOM does it become capable of having a reference.
var ref = $('page').insert(...);
But as you are calling this in a loop (essentially), you will need to
generate an array of refs.
ref[n] = $('page').insert(...);
Maybe.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--
You received this message because you are subscribed to the Google Groups
Prototype script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.