I'm confused about how to use Template:
$('curMedList').innerHTML=[conversion1, conversion2,
conversion3].each( function(conv){templ.evaluate(conv);});
this outputs "[object,Object],[object,Object],[object,Object]"
What am I doing wrong?
on 2008-06-26 00:22
on 2008-06-26 01:36
You're assigning the return value of each() to innerHTML, which is the array you're iterating over. What are you trying to do? -Fred On Wed, Jun 25, 2008 at 5:22 PM, Namotco <namotco@gmail.com> wrote: > > I'm confused about how to use Template: > > $('curMedList').innerHTML=[conversion1, conversion2, > conversion3].each( function(conv){templ.evaluate(conv);}); > > this outputs "[object,Object],[object,Object],[object,Object]" > > What am I doing wrong? -- Science answers questions; philosophy questions answers.
on 2008-06-26 02:43
Put the resulting HTML inside the element $('curMedList'). What
should I change?
on 2008-06-26 04:04
I changed my code to add the HTML inside of the function. Now my problem is the first time it's always undefined and I get that in my output: "undefined" <li>list item 1</li> <li>list item 2</li>
on 2008-06-26 04:39
given a JSON object and this:
<div id="curMedContainer">
<ul id="curMedList"></ul>
<br style="clear:both;" />
<div id="MedHistoryDisplay"></div>
</div>
I'm trying to use Template to fill in the list:
var cmHeader = new Template('<li class="#{active} #{RxNumber}"><a
href="\#Rx#{RxNumber}" id="cm_#{RxNumber}"
onclick="activateMedList(\'#{RxNumber}\');">#{ShortDate}</a></li>');
var mlhtml;
My_Array_Of_Objects.each( function(conv){mlhtml
+=cmHeader.evaluate(conv);});
$('curMedList').innerHTML=mlhtml;
on 2008-06-26 04:41
I fixed it be defining my variable first (var mlhtml; --> var mlhtml=''; ). Thanks for the help anyway.
on 2008-06-26 20:12
Template#evaluate method returns a string, you can assign this string
to an innerHTML object. Remember, "each" doesn't return anything so
assigning a value to the execution doesn't really work the way you're
anticipating it to in your first example. You could however use the
"collect" method and get some decent results like this.
$("curMedList").innerHTML = [obj1, obj2, obj3].collect(function(obj)
{ return myTemplate.evaluate(obj)});
--
Matt Foster
Ajax Engineer
Nth Penguin, LLC
http://www.nthpenguin.com
on 2008-06-26 21:10
Enumerable#collect() still returns an array though. If the template is
HTML, you could create a list with something like:
$("curMedList").innerHTML = [obj1, obj2, obj3].inject('<ul>',
function(s,
obj) {
return s + '\n<li>' + myTemplate.evaluate(obj) + '</li>';
}) + '\n</ul>';
You get the idea.
-Fred
On Thu, Jun 26, 2008 at 1:01 PM, Matt Foster <mattfoster01@gmail.com>
wrote:
>
> Template#evaluate method returns a string, you can assign this string
> to an innerHTML object. Remember, "each" doesn't return anything so
> assigning a value to the execution doesn't really work the way you're
> anticipating it to in your first example. You could however use the
> "collect" method and get some decent results like this.
>
> $("curMedList").innerHTML = [obj1, obj2, obj3].collect(function(obj)
> { return myTemplate.evaluate(obj)});
--
Science answers questions; philosophy questions answers.