O
O
Oleg2016-05-24 12:04:08
JavaScript
Oleg, 2016-05-24 12:04:08

How to parse a two-dimensional array into a table using ng-repeat?

The server returns an array in json, data is accessed as follows:
data[item][property]
Only certain columns need to be formatted as a table:

<table>
  <tr ng-repeat="item in data">
    <td>{{item[0]}}</td>
    <td>{{item[1]}}</td>
    <td>{{item[3]}}</td>
    <td>{{item[7]}}</td>
  </tr>
</table>

How is it possible to give each element of an array a title for readability, like item in data?
All that comes to mind is to convert each array to an object and assign a "talking" property to each index, but perhaps there is an elegant solution through angular directives?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nuclear_kote, 2016-05-24
@ptrvch

<table>
  <tr ng-repeat="item in data">
    <td ng-repeat="value in item">{{value}}</td>
  </tr>
</table>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question