//多级转一级对象中有children的数组,一级一级嵌套的多级转为一级
//参数data:{code1:'',code2:'',children:[{code3:'',code4:'',children:[{},{},{}]},{},{}]}
//返回值为数组[{code1:'',code2:'',code3:'',code4:'',...}]
function MultiToOne(data,item) {
let checkList = [];
let getOne = function (data,item) {
let objItem = item||{};
let {children,...others} = data;
objItem = {
...objItem,
...others,
};
if(typeof data === 'object'&&data.hasOwnProperty('children')){
for(let i = 0;i < data.children.length;i++){
getOne(data.children[i],objItem);
}
}else{
checkList.push(objItem);
}
};
getOne(data);
return checkList;
}