var result = await this.app.mysql.query('select * from sys_menu where pid = 0') // 获取顶级
var all = JSON.parse(JSON.stringify(result))
// 循环获取子集
// for (let i = 0; i < result.length; i++) {
// all[i]['all'] = await this.app.mysql.query('select * from sys_menu where pid = ?', [result[i].id])
// for (let j = 0; j < all[i]['all'].length; j++) {
// all[i]['all'][j]['all'] = await this.app.mysql.query('select * from sys_menu where pid = ?', [all[i]['all'][j].id])
// }
// }
// 递归获取子集
var tazh = this
async function isA(res) {
var r = []
if (res.length == 0) {
return
} else {
for (let i = 0; i < res.length; i++) {
res[i]['all'] = await isA(await tazh.app.mysql.query('select * from sys_menu where pid = ?', [res[i].id]))
r.push(res[i])
}
}
return r
}
all = await isA(result)
this.ctx.body = all
发表评论