0

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.

2 Answers 2

1

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

0

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';
    }

1 Comment

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 answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.