node.js - cycle for in template and "Cannot read property 'length' of undefined" error when compiling with jade -


so search function route /users/search:

// peopleroutes.js:25:16 exports.search = function (req, res) {     var term = req.query.term;     user.find({$or: [             {username:  {$in: [term]}},             {bio:       {$in: [term]}},             {location:  {$in: [term]}}           ]}, function (err, users) {                 var fn = jade.compilefile('path/to/template.jade'), {});                 var html = fn(users);                 res.setheader("content-type", 'text/html');                 res.send(html);                 res.end();     }).sort({username: 'asc'}); }; 

this template want retrieve:

ul.list-group(id='main-list')     user in users         li.list-group-item             div.col-md-3.no-padd-l                 img(src= user.gravatarurl, alt='avatar')                 div= user.location             div.col-md-9.no-padd-r                 div.strong= user.username                 div= user.bio 

i continue receive following error message:

c:\...\node_modules\jade\lib\runtime.js:240   throw err;         ^ typeerror: c:\.../path/to/template.jade:2     1| ul.list-group(id='main-list')   > 2|  - user in users     3|          li.list-group-item     4|                  div.col-md-3.no-padd-l     5|                          img(src= user.gravatarurl, alt='avatar')  cannot read property 'length' of undefined     @ eval (eval @ <anonymous> (c:\...\node_modules\jade\lib\index.js:218:8), <anonymous>:17:31)     @ eval (eval @ <anonymous> (c:\...\node_modules\jade\lib\index.js:218:8), <anonymous>:114:4)     @ eval (eval @ <anonymous> (c:\...\node_modules\jade\lib\index.js:218:8), <anonymous>:120:22)     @ res (c:\...\node_modules\jade\lib\index.js:219:38)     @ query.<anonymous> (c:\...\people\peopleroutes.js:25:16)     @ c:\...\mongoose\node_modules\kareem\index.js:177:19     @ c:\...\node_modules\mongoose\node_modules\kareem\index.js:109:16     @ process._tickcallback (node.js:355:11) 

i read there solution rid of "cannot read property 'length' of undefined" error message adding blank line @ end of .jade template doesn't work me. idea on can cause error? user.find query seems return correct values...

i needed use:

var html = fn(users: users); 

instead of

var html = fn(users); 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -