-
let label = item.controlName; item.label = label; delete item.controlName; let children = item.phenomenonCategoriesList.concat(); item.children = children; delete item.phenomenonCategoriesList;
利用第三方变量来暂存属性的value值,再将其添加进对象,删除对象中的原属性名。
缺点:当对象中数组和对象多层嵌套时,就很繁琐,且深层次的对象属性动态变化在Vue中还得使用vue.$set(obj,key,value)的方式来设置属性,才能被Vue监听。
2.
arr= JSON.parse(JSON.stringify(arr).replace(/controlName/g,“label”));
arr= JSON.parse(JSON.stringify(arr).replace(/phenomenonName/g,“label”));
arr= JSON.parse(JSON.stringify(arr).replace(/phenomenonCategoriesList/g,“children”));
arr= JSON.parse(JSON.stringify(arr).replace(/smallList/g,“children”));
第二种方式更高效,且不用担心嵌套深而不被vue监听的问题;拿到数据就做json转化。