有三组以下格式的数组数据,想将这三组中的数据合并,出现问题报错如下:TypeError:Cannotreadproperty'children'ofundefinedcategories:[{'id':0,'cname':''}]courses:[{'id':0,'category_id':0'coursename':'',}]chapter:[{'id':0,'courseid':0,'chaptername':''}]options:function(){letobj=newArray()letthat=this;for(leti=0;iobj.push({ 'value':that.categories[i].id,'label':that.categories[i].cname,'children':[],});for(letk=0;kif(that.categories[i].id==that.courses[k].category_id){ obj[i].children.push({'value':that.courses[k].id,'label':that.courses[k].coursename,'children':[]});}for(letj=0;jif(that.courses[k].id==that.chapters[j].courseid){ obj[i].children[k].children.push({//这里报错'value':that.chapters[j].id,'label':that.chapters[j].chaptername,})}}}}returnobj}
Smart猫小萌
相关分类