0
我有MongoDB數據庫文件其中包含數組奇怪MongoDB的響應格式
{
"_id":ObjectId("588116a66f7d758b144177f7"),
"name":"Michael",
"email":"[email protected]",
"company":"Shift",
"username":"MichaelP",
"password":"$2a$10$unH/7anPylxk1x5zk6/so.YcByZqQoBdFi9IlWnHty2gNouUrt7ea",
"position":"Manager",
"shifts":[
"day",
"day",
null,
"night",
null,
null,
null,
"15"
],
"score":[
null,
"550",
null
],
"__v":0
}
我想在我的網頁打印出來shifts[7]
。我是新來的node.js,但我可以打印{{username}}
或{{company}}
罰款shifts[7]
打印'{ '0': '1', '1': '5' }'
我想這是一個簡單的解決方案在我的index.js但我似乎無法弄清楚。
我在下面添加我的index.js代碼的縮短版本,並感謝您的幫助。
router.get('/hub',ensureAuthenticated, function(req, res, next){
var collection = db.collection('users');
var totalHours= req.user.shifts[7] + '';
var totalhour=0;
res.render('hub', {username: req.user.username,
company: req.user.company,
position: req.user.position,
totalHours: totalhour
});
});
你嘗試'VAR totalHours = req.user.shifts [7]。加入( '')'? –
你正在使用嵌套數組錯誤。嵌套數組應該包含對象。 – Tom
謝謝,@JyothiBabuAraja它說,req.user.shifts [7] .join不是一個函數,我應該單獨編寫函數嗎? – LiveLongCandy51