猿问

Javascript代码的小小疑问(81)——js动态插值

/***************************
*如何循环8次,生成如下JSON结构
****************************/

var labels = ["R","A","B","C","D","E","F","G"];
var JSON_DATA = new Object(); 
var ARR_1 = new Array();
var ARR_2 = new Array();

//To do?
//...

JSON_DATA["x"] = ARR_1;
JSON_DATA["y"] = ARR_2;


/***************************
*希望生成后的JSON结构
****************************/

JSON_DATA = {
    "x":[{
       nIndex:0,
       name:"R",
       basic:{
            R1:"",
            R2:"",
            R3:"",
            R4:""
    },{
       nIndex:1,
       name:"A",
       basic:{
            B1:"",
            B2:"",
            B3:"",
            B4:""
          }
    },{
       nIndex:2,
       name:"B"
    },{
       nIndex:3,
       name:"C"
   },{
       nIndex:4,
       name:"D"
   },{
       nIndex:5,
       name:"E"
   },{
       nIndex:6,
       name:"F"
   },{
       nIndex:7,
       name:"G"
   }
 ],
    
    "y":[{
       source:0,
       target:1
      },{
       source:0,
       target:2
      },{
       source:0,
       target:3
      },{
       source:0,
       target:4
      },{
       source:0,
       target:5
      },{
       source:0,
       target:6
      },{
       source:0,
       target:7
      },       
    ]

}
            
浮云间
浏览 473回答 5
5回答

婷婷同学_

可以先把json结构列好,就可以直接嵌插了

子衿沉夜

你完美解答了我的问题;

喵喔喔

看了半天没看懂关联 R1:"", R2:"", R3:"", R4:""       //这个后面缺少了一个}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答