getOutData() {
// searchCategoryBySpecialId 调用的外层数据接口
searchCategoryBySpecialId({specialId: this.id}, data => {
if(data.categoryPOList && data.categoryPOList.length) {
let arr = []
data.categoryPOList.forEach(async(item,index) => {
let obj = {}
obj.title = item.typeName
obj.id = item.id
obj.list = await this.getInData(item.id)
arr.push(obj)
})
this.datalist = arr // datalist 为最终所需要的数据
}
})
},
getInData(categoryId) {
let params = {
specialId: this.id,
categoryId
}
// 使用promise将数据返回
const promise = new Promise((resolve,reject) => {
ajaxSearchSpecialCourseListByCategoryId(
params,
data => {
resolve(data.list || [])
},
errorMsg => {
reject(errorMsg)
},
false
)
})
return promise
},
所得到的数据形式如下: