jquery - Automatically push / nest object within a parent object in JavaScript -


i working on excel behaviour task. "tr"s bound variable $test

var $test = $('tbody tr'); 

now use jquery .each function run throuhg trs , collect relevant contents :

$test.each(function(index, element){     var $row_id = $(this).data("rowid");     var status = $(this).find('#status option:selected').val();     var ma_name = $(this).find('#ma-name').val();     var datum = $(this).find('#datum').val();     var firmenname1 = $(this).find('#firmenname1').val();     var firmenname2 = $(this).find('#firmenname2').val();     var limit = $(this).find('#limit').val();     var gruppe_kredit = $(this).find('#gruppe_kredit').val();      var omv_kdnr = $(this).find('#omv_kdnr').val();      var sap_kdnr = $(this).find('#sap_kdnr').val();      var fos = $(this).find('#fos').val();      var hga_kdnr = $(this).find('#fos').val();      var pushobj = {row_id: $row_id,....}; }); 

since pushobject gets greated , stuffed content each time each function gets executed need way "push" object parent object can later use ajax.

the behaviour i'd wish this:

var parentobj = {};  $.each(function(){ // in each run newly created object gets nested parentobject results in parent object having x-childobjects }); 

so after, lets 5 each runs, parentobj should contain : [0],[1],...,[4] objects.

could guide me throuhg process ?

try solution storing pushobj inside array variable :

// add here var parentobj = []; $test.each(function (index, element) {     var $row_id = $(this).data("rowid");     var status = $(this).find('#status option:selected').val();     var ma_name = $(this).find('#ma-name').val();     var datum = $(this).find('#datum').val();     var firmenname1 = $(this).find('#firmenname1').val();     var firmenname2 = $(this).find('#firmenname2').val();     var limit = $(this).find('#limit').val();     var gruppe_kredit = $(this).find('#gruppe_kredit').val();      var omv_kdnr = $(this).find('#omv_kdnr').val();      var sap_kdnr = $(this).find('#sap_kdnr').val();      var fos = $(this).find('#fos').val();      var hga_kdnr = $(this).find('#fos').val();       var pushobj = {         row_id: $row_id,         ....     };     // add here    parentobj.push(pushobj);  });  // later on here access parentobj variable 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -