Express + EJS partials - Recursion

583 views
Skip to first unread message

Merhawie Woldezion

unread,
Nov 28, 2011, 7:25:15 PM11/28/11
to expre...@googlegroups.com
Basically I am having trouble sending information in my recursive partial call

app.js
res.render('list.ejs', {locals: {list: list}})

list.ejs
list.foreach(function(v,i,a){
if v.sub.length>0 //v.sub is an array
partial('', {collection: v.sub, as: global}) 
}) 

i get a range error on the partial line.

For some reason I am sure the variable v.sub is not be going back into the foreach. I can't figure out why. Any ideas? 

vision media [ Tj Holowaychuk ]

unread,
Nov 30, 2011, 9:29:01 AM11/30/11
to expre...@googlegroups.com
that doesn't even look like javascript, it's array.forEach and if needs parens, and
your partial() call has no view name

--
You received this message because you are subscribed to the Google Groups "Express" group.
To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/4ntNifrSRsEJ.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.



--
Tj Holowaychuk
Vision Media
President & Creative Lead

Merhawie Woldezion

unread,
Nov 30, 2011, 9:44:41 AM11/30/11
to expre...@googlegroups.com
Sorry TJ, i was just trying to be concise (in my haste i think i went too far!)

app.js
res.render('list.ejs', {locals: {list: list}}) // list looks like [{sub: someArray}, {sub: [{sub: []}]}]

list.ejs
list.foreach(function(v,i,a){
if v.sub.length>0 //v.sub is an array
partial('list.ejs', {locals: {list: v.sub}}) 

vision media [ Tj Holowaychuk ]

unread,
Nov 30, 2011, 9:47:59 AM11/30/11
to expre...@googlegroups.com
oh i see :D

hmm it appears ok. on a side note i would do app.set('view engine', 'ejs') and then:

app.js

res.render('list', { list: list });

list.ejs

  change partial to partial('list', { object: v.sub }) should work

--
You received this message because you are subscribed to the Google Groups "Express" group.
To view this discussion on the web visit https://groups.google.com/d/msg/express-js/-/2owpf04q22gJ.

To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.

vision media [ Tj Holowaychuk ]

unread,
Nov 30, 2011, 9:48:36 AM11/30/11
to expre...@googlegroups.com
unless you are actually exhausting the stack in which case you just have too much nesting im not sure 

Merhawie Woldezion

unread,
Nov 30, 2011, 9:55:29 AM11/30/11
to expre...@googlegroups.com
TJ, 

Awesome! Thank you! The object change fixed it right away!
Reply all
Reply to author
Forward
0 new messages