I want to store the data in to multidimensional arrays or object and send the data to the controller. I have defined the object in javascript like
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;
If the see the json content then it is displaying only the latest information. but it is not showing the content that is saved earlier. how can i save the content.
asked Oct 24, 2013 at 15:19
Jonathan
1,6699 gold badges36 silver badges55 bronze badges
2 Answers 2
The problem is that you are overriding: dynamicprofile.profilename, dynamicprofile.idarray and dynamicprofile.trueorfalse.
Maybe you can try one of these solutions among others:
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
});
Sign up to request clarification or add additional context in comments.
Comments
u can do it in following way
var a=new Array();
for(vr i=0;i<10;i++)
{
a[i]=new Array();
a[i][0]='value1';
a[i][1]='value2';
}
answered Oct 24, 2013 at 15:28
Vicky Gonsalves
11.8k3 gold badges39 silver badges58 bronze badges
1 Comment
Jonathan
yah i have found another way. I have taken another object
var objname = {}; and for the first obj objname["cert"] and for the second object objname["projects"]. thanks for the answerlang-js