老师有此部分代码,我想使用foEach或地图或过滤器循环此部分名称
"section": [
{
"name": "AA12",
"subjects": [
"PJ"
]
},
{
"name": "AA13",
"subjects": [
"DFM",
"PJ"
]
}
]
时间表具有此数组。
{
"_id": {
"$oid": "5cb31e0c7ee5c600173d5812"
},
"date": [
{
"time1": "ISM",
"time2": "DBMA",
"time3": "IRA",
"time4": "BB"
},
{
"time1": "DFM",
"time2": "ITP",
"time3": "DBE",
"time4": "PJ"
},
{
"time1": "ISM",
"time2": "DBMA",
"time3": "ITP",
"time4": "DBE"
},
{
"time1": "PJ",
"time2": "IRA",
"time3": "IRA",
"time4": "ISM"
},
{
"time1": "ITP",
"time2": "DBMA",
"time3": "DBE",
"time4": "PJ"
}
],
"sectionID": "AA12",
"__v": 0
}
我正在遍历部分。如果时间表名称中包含该部分的名称,则它将返回日期
我正在使用异步功能,并且通过显示“名称为{}”不返回任何内容。我只是异步功能的初学者。
let timetableFunc = async (name) => {
let a = timetable.find({ sectionID: name }).exec()
return a.then(result => {
if (result[0] !== undefined) {
console.log(result[0])
return result[0]
}
})
}
let asyncf = async () => {
let arr = await sections[0].section.map(sect => {
let name = timetableFunc(sect.name);
console.log(`name is ${JSON.stringify(name)}`);
})
}
asyncf()