如果是一个数组包含对象且每个都对象内部固定包含child子数组,命名规范的话,使用for in就行了,去判断每一集下面还有没有child: [ ],
但是现在碰到不规则的json对象就很棘手,参数完全不确定,只能使用递归了,先贴代码:
watch:{ colorData: { handler() { console.log("颜色变更========", this.componentList); function findColorText(obj) { for (var i in obj) { //判断是否为object 有就再从此层级开始循环 if (typeof (obj[i]) == "object") { findColorText(obj[i]); //递归遍历所有下层对象 } else { if(i === 'color'){ //找出参数名为color obj[i] = 'blue'; // 当前循环对象的参数为color 赋值为blue console.log(i,"找到所有名为color的参数---",obj[i]); } } } } findColorText(this.componentList) } }, deep:true},watch中监听获取json对象,调用递归方法即可。
个人纪录,仅供参考!
快三三期必中口诀找出参数名为color obj[i] = 'blue'; // 当前循环对象的参数为color 赋值为blue console.log(i,"找到所有名为color的参数---",obj[i]); } } } } findColorText(this.componentList) } }, deep:true},watch中监听获取json对象,调用递归方法即可。
个人纪录,仅供参考!