javascript - using lodash to generate a dynamic table in nested object -


i have got nested object containing students' details below:

data = [             {                 name: 'gill, jack',                 subjects: [                     {                         name: 'mathematics',                         scores: [                             {                                 year: 7,                                 collection: 1,                                 score: 430,                              },                             {                                 year: 7,                                 collection: 2,                                 score: 500,                              }                         ]                     } 

} going generate dynamic table in webpage show last year's mark each student. unfortunately not working , prints n/a , think there wrong lodash new it. used static array instead of scoreatl , table had correct cell contents.

//getting students id url $.get('/rest/report/' + upn, function (data) { ... data.subjects.foreach(function (subject) {                  html += '<tr>';                 html += '<td>' + subject.name + '</td>';                 (var j = 0; j < data.cyclenumber; ++j) {                       var scoreatl = _.findwhere(subject.scores, { year: data.yearforatl, collection: j });                      if (scoreatl.score)                         html += '<td>' + scoreatl.score + '</td>';                     else                         html += '<td>' + 'n/a' + '</td>';                 }                 html += "</tr>";             }); ... } 

i tried approach , shows n/a in cells:

data.subjects.foreach(function (subject) {                 html += '<tr>';                 html += '<td>' + subject.name + '</td>';                 (var j = 0; j < data.cyclenumber; ++j) {                      var scoreatl = 0;                     scoreatl = _.result(_.findwhere(subject.scores, { year: data.yearforatl, collection: j }), score);                      if (scoreatl)                         html += '<td>' + scoreatl + '</td>';                     else                         html += '<td>' + 'n/a' + '</td>';                 }                 html += "</tr>";             }); 


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -