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