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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Put the resulting HTML inside the element $(''curMedList''). What should I change? On Jun 25, 6:36 pm, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote:> 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 <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
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 Jun 25, 7:40 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Put the resulting HTML inside the element $(''curMedList''). What > should I change? > > On Jun 25, 6:36 pm, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote: > > > 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 <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
What exactly are you trying to do? - kangax On Jun 25, 10:03 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 Jun 25, 7:40 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Put the resulting HTML inside the element $(''curMedList''). What > > should I change? > > > On Jun 25, 6:36 pm, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote: > > > > 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 <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
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; --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I fixed it be defining my variable first (var mlhtml; --> var mlhtml=''''; ). Thanks for the help anyway. On Jun 25, 9:15 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> What exactly are you trying to do? > > - kangax > > On Jun 25, 10:03 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 Jun 25, 7:40 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Put the resulting HTML inside the element $(''curMedList''). What > > > should I change? > > > > On Jun 25, 6:36 pm, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote: > > > > > 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 <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
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 Jun 25, 10:41 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I fixed it be defining my variable first (var mlhtml; --> var > mlhtml=''''; ). Thanks for the help anyway. > > On Jun 25, 9:15 pm, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > What exactly are you trying to do? > > > - kangax > > > On Jun 25, 10:03 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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 Jun 25, 7:40 pm, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Put the resulting HTML inside the element $(''curMedList''). What > > > > should I change? > > > > > On Jun 25, 6:36 pm, "Frederick Polgardy" <f...-SMQUYeM9IBBWk0Htik3J/w@public.gmane.org> wrote: > > > > > > 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 <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---