我正在使用mongodb
和express
获取数据,虽然没有出现错误,但我想在我的.find
的最终结果中使用JSON.parse
。请参考下面我尝试这样做的方式:
app.get("/login", (req, res) => {
var credentialClient = {
expire_at: false,
__v: false,
_id: false
};
rememberMe.find({ username: "test-login" }, credentialClient, function (err, credentialInfo) {
if (err) {
res.send(err);
} else {
res.render("login.html", {
usernameClient: JSON.parse(credentialInfo)
});
}
});
});
如果没有JSON.parse
,我的login.html
页面的最终呈现会保持不变。
{ username: 'test-login' }
最终结果将出现在
login.html
中。<p class="center-align black-text" id="preFinalCredentialClient">{{ usernameClient }}</p>
谢谢你的帮助!
credentialInfo
(来自mongo.find()的结果)已经是JSON格式了。你不需要调用JSON.parse()
。 - Alongkornjson
中,但在渲染{{ usernameClient }}
数据时,返回的数据格式混乱无序,出现了很多问题,在我的<p class="black-text center-align">{{ usernameClient }}</p>
中。 - Gabriel