how to render json object in jade and loop through results

Deadly 提交于 2019-11-27 18:51:56

Why are you passing a string? Try this:

var ob = { action:"date +%s", result:"1367263074"};
res.render('index', { layout : 'layout', json: ob });

Or do this:

-var ob = JSON.parse(json)
-for(var prop in ob)
 p #{prop}: #{ob[prop]}

On this line : each val, key in json You stringified your JS Object first (server-side), don't stringify it to get it as object.

So this line :

res.render('index', { layout : 'layout', json: JSON.stringify(json_string) });

becomes

res.render('index', { layout : 'layout', json: json_string });

If you are looking for looping over an array of actions and results, then use Mathieu Amiot's suggestion plus this code:

each key in json   
    p !{key.action} !{key.result}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!