根据后端返回的年级id数组回显选中的年级
gradeList = [
{id:'1',name:'初一'},
{id:'2',name:'初二'},
{id:'3',name:'初三'},
{id:'4',name:'高一'},
{id:'5',name:'高二'},
{id:'6',name:'选项名称6'}
]
gradeIds = [
{id:'1'},
{id:'2'},
{id:'3'}
]
// 打开弹窗回显年级数组,选中的打勾
let arr = this.data.gradeList.map((item, index) => {
item.isActive = false // 先设置所有的年级为未选中
// 遍历选中的年级Id数组
this.data.gradeIds.map((item2, index2) => {
// 再判断有相同项的设置为选中
if(item.id == item2) {
item.isActive = true
}
})
return item
})
this.setData({
gradeList: arr
})