{
"nome": "Mario",
"cognome": "Rossi",
"user": "Mario00",
"email": "mariorossi@gmail.com",
"pass": "688787d8ff144c502c7f5cffaafe2cc588d86079f9de88304c26b0cb99ce91c6",
"dataNascita": {$date:"1999-04-10T00:00:00.389Z"},
"pos": {
"lng" : 45.4773,
"lat" : 9.1815
},
"genere": "M",
"mailConfermata": "ga8sg90g",
"appunti": [
{
"id": "f7onotwkvjdlak9v",
"titolo": "Giovanni Pascoli",
"descrizione": "Riassunto della vita di pascoli",
"dataCaricamento": "2018-05-25T18:56:24.443Z",
"percorsoFile": "pascoli.docx",
"tags": [
"pascoli",
"italiano",
"vita",
"riassunto",
"poesia"
]
},
{
"id": "dbvuyjt6z25zurhn",
"titolo": "Napoleone Bonaparte",
"descrizione": "Riassunto di Napoleone Bonaparte",
"dataCaricamento": "2018-05-25T19:10:50.914Z",
"percorsoFile": "NapoleoneBonaparte.docx",
"tags": [
"storia",
"napoleone",
"imperatore",
"francia",
"waterloo"
]
},
{
"id": "bib2c6j3lrj3wogu",
"titolo": "Dante Alighieri",
"descrizione": "riassunto della divina commedia",
"dataCaricamento": "2018-05-25T20:56:43.989Z",
"percorsoFile": "divinaCommedia.docx",
"tags": [
"dante",
"letteratura",
"divina",
"commedia",
"italiano"
]
},
{
"id": "st4xvwmollzrwc6r",
"titolo": "Integrali",
"descrizione": "Riassunto su integrali",
"dataCaricamento": "2018-05-26T10:21:13.297Z",
"percorsoFile": "POWERPNT.EXE",
"tags": [
"matematica",
"riassunto"
],
"commenti": [
{
"id": "zcrhxqoxc1jqkn28",
"autore": "nomeUtenteCookie",
"idAutore": "idNomeUtenteCookie",
"dataCaricamento": "2018-05-27T09:15:14.882Z",
"testo": "lalalalal"
},
{
"id": "xntpzyvy3lep7ipu",
"autore": "nomeUtenteCookie",
"idAutore": "idNomeUtenteCookie",
"dataCaricamento": "2018-05-27T09:16:15.680Z",
"testo": "hfaaeuIOGFNAIUOVBNUIABNPUAIBVBDAS"
},
{
"id": "15sciqvmkegxr5zt",
"autore": "nomeUtenteCookie",
"idAutore": "idNomeUtenteCookie",
"dataCaricamento": "2018-05-27T09:16:40.035Z",
"testo": "y'all"
},
{
"id": "wnfjc48vwm8zfxi4",
"autore": "nomeUtenteCookie",
"idAutore": "idNomeUtenteCookie",
"dataCaricamento": "2018-05-27T09:17:20.004Z",
"testo": "olololo"
}
],
"voti": [
{
"idVotante": "idNomeUtenteCookie",
"voto": 10
}
],
"votoMedio": 10
}
]
}
我想在一个表中显示剪贴板数组中的每个元素,但它只让我看到数组的第一个对象,你能解释一下我错在哪里吗? 我在search.js的代码部分使用了一个forach循环,但是我可以看到它无法完全滚动剪贴板,因为在表中它只显示了第一个遇到的对象,不应该如此
的NodeJS(index.js):
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("mydb");
dbo.collection("user").find({username: "mario00"}, {
fields: {appunti: 1, "_id": 0}
}).toArray(function(err, result) {
if (err) throw err;
console.log(result)
res.render('cerca', {
listaAppunti: result
});
db.close();
});
});
JADE(cerca.jade):
// TABLE APPUNITI
.table-responsive
table
th Titolo
th Data
th Percorso
th Tags
tr
each appunto, i in listaAppunti
td
a(href='https://myproject-codeanyapp.com/commenti?id=' + appunto.appunti[i].id) #{appunto.appunti[i].titolo}
td=appunto.appunti[i].dataCaricamento
td
a(href='https://myproject-codeanyapp.com/files/' + appunto.appunti[i].percorsoFile, download='') #{appunto.appunti[i].percorsoFile}
td
each tag in appunto.appunti[i].tags
a(href='https://myproject-codeanyapp.com/appunti?tags=' + tag) #{'#'+tag}
答案 0 :(得分:0)
但它只让我看到数组的第一个对象,你能解释一下我错在哪里吗?
这是因为每个元素中的appunti
是一个数组。您需要额外的each
循环来迭代appunti
元素。
对您的代码进行此更改
.table-responsive
table
th Titolo
th Data
th Percorso
th Tags
each appunto in listaAppunti
each item in appunto.appunti
tr
td
a(href='https://myproject-codeanyapp.com/commenti?id=' + item.id) #{item.titolo}
td=item.dataCaricamento
td
a(href='https://myproject-codeanyapp.com/files/' + item.percorsoFile, download='') #{item.percorsoFile}
td
each tag in item.tags
a(href='https://myproject-codeanyapp.com/appunti?tags=' + tag) #{'#' + tag}