【发布时间】:2015-01-26 00:21:23
【问题描述】:
我有一个使用 EJS 模板的主页,
我想使用 URL 中的用户 id 显示用户名(不是现在登录的用户)
页面是这样调用的:
/home?id=235325325235
这里是 home.ejs 的一部分:
<!-- i want to get the username or other info of another user -->
<p> Hello <%= get.otheruser.name(id) %> </p>
这是我的 routes.js 的一部分
// load up the user model
var User = require('../app/models/user');
app.get('/home', function(req, res) {
res.render('home.ejs', {
id : req.query.id,
otheruser : User.findById( req.query.id ), //error this doesn't get the info i need
currentuser : req.user //ignore this, this is the information of the current logged in user
});
});
但是,如果登录的用户想要查看其他用户的主页会怎样?
他会用其他用户的id调用主页,
/home?id=43565476535
我需要一个使用 URL 中的 ID 获取所有信息的函数
node.js 是如何做到这一点的?
【问题讨论】:
标签: node.js mongodb function mongoose ejs