admin管理员组文章数量:1333201
So I have this JSON array apiData
being passed on to the view as data
.
Backend
router.get('/', function(req, res) {
var data = JSON.stringify(apiData);
res.render('gallery', { data: apiData });
});
Frontend
extends layout
block content
h1 MyProject
!{JSON.stringify(data)}
I am trying to cache !{JSON.stringify(data)}
in a variable and iterate through it in the jade file. I am pletely new to jade. How could I go about doing this?
So I have this JSON array apiData
being passed on to the view as data
.
Backend
router.get('/', function(req, res) {
var data = JSON.stringify(apiData);
res.render('gallery', { data: apiData });
});
Frontend
extends layout
block content
h1 MyProject
!{JSON.stringify(data)}
I am trying to cache !{JSON.stringify(data)}
in a variable and iterate through it in the jade file. I am pletely new to jade. How could I go about doing this?
- You could use Objects.key(data) and for (k in Objects.key(data)){//access to each value like; data[k];} – kahonmlg Commented Jan 26, 2015 at 11:56
- Could you post a link to code at repl.it or jsfiddle? – ng-hacker-319 Commented Jan 26, 2015 at 12:02
1 Answer
Reset to default 5You have a few problems in your code, like not using the stringification you do server side at all.
But you don't even need JSON here. Simply pass the array and iterate on it :
Backend
router.get('/', function(req, res) {
res.render('gallery', { data: apiData });
});
Frontend
extends layout
block content
h1 MyProject
each thing in data
p= thing
You'll find examples of iteration in the documentation
本文标签: javascriptHow do I iterate over a JSON array using Jade and NodejsStack Overflow
版权声明:本文标题:javascript - How do I iterate over a JSON array using Jade and Node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742277082a2445397.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论