Alternatively nested array values json

For json data from the background brought not necessarily meet the demand, the need for data to make some adjustments.
json data was as follows

0
   id :10001
   parent : #
   text : 实例1
   state : 
              selected :true
1
   id :10002
   parent : #
   text : 实例2
   state : 
              selected :false
2
   id :10003
   parent : 10002
   text : 实例3
   state : 
              selected :false
......

Demand does not require three-tier structure, I will change it to two-tier structure.


this.roleaddlist.forEach((val,index)=>{
					if(val["state"]['selected']==true){
						val["state"]=true;// 修改 把state修改成true
					}else{
						val["state"]=false;// 修改 把state修改成false
					}
				});

Wherein the JavaScript forEach () method calls for each element of the array, and passed to the callback function element.
jQuery attribute operations - val () method returns a value or set of the selected element
ps: vue parentheses here is the code format, and "" is the format code json array.
This is done to modify the code.

0
   id :10001
   parent : #
   text : 实例1
   state : true
1
   id :10002
   parent : #
   text : 实例2
   state : false
2
   id :10003
   parent : 10002
   text : 实例3
   state : false
......

Guess you like

Origin blog.csdn.net/weixin_44724060/article/details/88266067