我想将数据存储到多维数组或对象中,并将数据发送到控制器。我已经在javascript中定义了对象
var dynamicprofile = new Object();
var certidarry = [];
var trueorfalse = [];
dynamicprofile.profilename = "certifications";
$(".certclass").each(function (index, element) {
certidarry.push(i);
if (element.checked == false) {
trueorfalse.push(false);
}
else if (element.checked == true) {
trueorfalse.push(true);
}
});
dynamicprofile.idarray = certidarry;
dynamicprofile.trueorfalse = trueorfalse;
dynamicprofile.profilename = "projects";
var projectidarry12 = [];
var trueorfalsearry12 = [];
$(".Projectsclass").each(function (index, element) {
projectidarry12.push(index);
if (element.checked == false) {
trueorfalsearry12.push(false);
}
else if (element.checked == true) {
trueorfalsearry12.push(true);
}
});
dynamicprofile.idarray = projectidarry12;
dynamicprofile.trueorfalse = trueorfalsearry12;
如果看到json
内容,那么它只显示最新信息。但它没有显示先前保存的内容。我该如何保存内容。
答案 0 :(得分:1)
问题是你要覆盖:dynamicprofile.profilename,dynamicprofile.idarray和dynamicprofile.trueorfalse。
也许您可以尝试其中一种解决方案:
1
var dynamicprofile = new Object();
var certidarry = [];
var trueorfalse = [];
dynamicprofile['certifications'] = {};
$(".certclass").each(function (index, element) {
certidarry.push(index);
if (element.checked == false) {
trueorfalse.push(false);
}
else if (element.checked == true) {
trueorfalse.push(true);
}
});
dynamicprofile['certifications'].idarray = certidarry;
dynamicprofile['certifications'].trueorfalse = trueorfalse;
dynamicprofile['projects'] = {};
var projectidarry12 = [];
var trueorfalsearry12 = [];
$(".Projectsclass").each(function (index, element) {
projectidarry12.push(index);
if (element.checked == false) {
trueorfalsearry12.push(false);
}
else if (element.checked == true) {
trueorfalsearry12.push(true);
}
});
dynamicprofile['projects'].idarray = projectidarry12;
dynamicprofile['projects'].trueorfalse = trueorfalsearry12;
-
2
var dynamicprofile = [];
var certidarry = [];
var trueorfalse = [];
$(".certclass").each(function (index, element) {
certidarry.push(index);
if (element.checked == false) {
trueorfalse.push(false);
}
else if (element.checked == true) {
trueorfalse.push(true);
}
});
dynamicprofile.push({
profilename: "certifications",
idarray: certidarry,
trueorfalse: trueorfalse
});
var projectidarry12 = [];
var trueorfalsearry12 = [];
$(".Projectsclass").each(function (index, element) {
projectidarry12.push(index);
if (element.checked == false) {
trueorfalsearry12.push(false);
}
else if (element.checked == true) {
trueorfalsearry12.push(true);
}
});
dynamicprofile.push({
profilename: "projects",
idarray: projectidarry12,
trueorfalse: trueorfalsearry12
});
答案 1 :(得分:0)
var a=new Array();
for(vr i=0;i<10;i++)
{
a[i]=new Array();
a[i][0]='value1';
a[i][1]='value2';
}