0
私は私のウェブページshifts[7]
を印刷するアレイ奇妙な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
}
が含まれているのMongoDBデータベース文書を持っています。私は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
});
});
あなたは '[7] .join( '')'するvar totalHoursの=のreq.user.shiftsを試してみましたか? –
入れ子配列を間違って使用しています。ネストした配列にはオブジェクトが含まれている必要があります。 – Tom
ありがとう、@ JyothiBabuAraja req.user.shifts [7] .joinは関数ではないと言いますが、別途関数を書くべきですか? – LiveLongCandy51