当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript it dosen't work push() in array

问题描述:

hi i don't understand this situation. i want to insert data to Forms array.

Forms[0] data is string as "A". i want to insert data Forms[0]. for example, when i run code,

i want to result

Before:

 Forms:[{

"name":"A"

}]

After: ->>i want to result!!

 Forms:[{

"name":"A",

"Layout":[{

"a":a

}]

}

]

Code:

var Forms=[];

var FormsData={};

var Vidgets=[];

var VidgetData={};

var layoutData={};

var GridSeq=0;

for(var i=0;i<allForm.length;i++){

FormsData.NAME=allForm[i].title;

Forms.push(FormsData.NAME);

}

var Zones=0;

for(var i=0;i<allForm.length;i++){

for(var j=0;j<allForm[i].getChildren().length;j++){

//console.log(allForm[i].getChildren()[j].nbZones);

Zones=allForm[i].getChildren()[j].nbZones;

GridSeq++;

layoutData.Zones=Zones;

layoutData.GridSeq=GridSeq;

layout.push(layoutData);

Forms[i].Layout=layout[j];---->it dosen't work

layoutData={};

}

}

网友答案:

Your Json Which you are passing is not correct

var Forms={name:'', Layout:''}

and then pass it like

Forms.push({name:FormsData.NAME, Layout: {'a':layoutData} });

分享给朋友:
您可能感兴趣的文章:
随机阅读: