Home > Blockchain >  How to read array of array in jquery
How to read array of array in jquery

Time:04-06

my ajax call is returning 3000 records but js is returning 3000 records as 0-99,100-199 so on.... of 3000 records. how can i read all records and bind them into Datatable.

enter image description here

Also getting this error

Cannot read properties of undefined (reading 'length')

$.each(response.getResourcesCostings, function(m, n) {
  $('#rescostingbodyid').append('<tr>'    '<td></td>'    '<td>'   n.Name   '</td>'    '<td>'   n.type   '</td>'    '<td>'   n.location   '</td>'    '<td>'   n.total   '</td>'    '</tr>');
});

CodePudding user response:

Your concatenation has way too many signs: '<td>' for example. Strip out the ones you don't need which are causing the code to fail.

If there's an error about length it's not coming from the code you posted in your question.

const response = {
  getResourcesCostings: [
    {Name: '1', type: '1', location: '1', total: '1'},
    {Name: '2', type: '2', location: '2', total: '2'}
  ]
};

$.each(response.getResourcesCostings, function(m, n) {
  $('#rescostingbodyid').append('<tr>'   '<td>'   n.Name   '</td>'   '<td>'   n.type   '</td>'   '<td>'   n.location   '</td>'   '<td>'   n.total   '</td>'   '</tr>');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tbody id="rescostingbodyid"></tbody>
</table>

CodePudding user response:

Looks like it's just console optimization. Try JSON.stringify and check what it returns.

  • Related