【发布时间】:2015-09-26 08:25:54
【问题描述】:
我这里有简单的代码。
它的目的是验证用户与写帖子的用户,并允许经过验证的用户编辑帖子。
exports.edit = function(req, res){
Post.findById(req.params.post_id, function(err, post){
if(err){
return res.json({
type:false,
message:"error!"
});
}else if(!post){
return res.json({
type:false,
message:"no post with the id"
})
}else{
console.log(req.user._id, typeof req.user._id);
console.log(post.author.user_id, typeof post.author.user_id);
if(req.user._id === post.author.user_id){ // doesn't work!!
return res.json({
type:false,
message:"notAuthorized"
});
}else{
return res.json({
type:true,
message:"it works",
data:post
});
}
}
});
}
控制台说:
557c6922925a81930d2ce 'object'
557c6922925a81930d2ce 'object'
这意味着它们在值上相等,在类型上也相等。
我也尝试过==,但这也不起作用。
我怀疑需要做一些事情来比较对象,但我不知道我应该做什么。
【问题讨论】:
-
很奇怪这些被记录为字符串但他们说它们是对象。如果它是一个
String对象,那么您会看到除了字符串值之外的一堆其他内容。 -
JavaScript 中什么样的对象记录了字符串值但不是原始字符串?
标签: javascript node.js