问题
i have really important question about jade and node.js usage. i have a userlist function in node.js. i wanna show my json data in side of node.js as jade page. but it will be empty.
i have 2 file: USERLIST.jade and index.js
index.js:
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function (req, res) {
res.render('index', { title: 'Express' });
});
/* GET Userlist page. */
router.get('/userlist', function (req, res) {
var json = { name: "yusuf karatoprak", age: 42 };
res.render('userlist', { userlist : json });
});
module.exports = router;
USERLIST.jade
extends layout
block content
h1.
User List
ul
each user, i in userlist
li
#{user.name}
but it creates empty page. i can not see my json data...
回答1:
Try this...
extends layout
block content
h1.
User List
ul
li= userlist.name
回答2:
You're passing a JavaScript object, not an array. You don't need to loop it.
Either change your data to:
var json = [{ name: "yusuf karatoprak", age: 42 }];
Or change your view to:
extends layout
block content
h1.
User List
ul
li
#{userlist.name}
回答3:
This must work-
extends layout
block content
h1.
User List
ul
each user, i in userlist
li #{user}
来源:https://stackoverflow.com/questions/27966173/how-to-send-json-data-to-jade-from-node-js