angularjs - Ng-repeat on generic element -
i have problem. make ng-repeat on different json depending on call.
i want this: when call made on elementheaderatmt display following code
<table class="table"> <thead> <tr ng-repeat="element in elementsheaderatmt"> <th>{{ element.transportline }}</th> <th>{{ element.station }}</th> <th>{{ element.transformer }}</th> <th>{{ element.park }}</th> <th>{{ element.linemt }}</th> <th>{{ element.section }}</th> <th>{{ element.cd }}</th> <th>{{ element.transformercdcm }}</th> <th>{{ element.element }}</th> <th>{{ element.type }}</th> </tr> </thead> <tbody> <tr ng-repeat="element in elementsdataatmt"> <td>{{ element.transportline }}</td> <td>{{ element.station }}</td> <td>{{ element.transformer }}</td> <td>{{ element.park }}</td> <td>{{ element.linemt }}</td> <td>{{ element.section }}</td> <td>{{ element.cd }}</td> <td>{{ element.transformercdcm }}</td> <td>{{ element.element }}</td> <td>{{ element.type }}</td> </tr> </tbody> </table>
otherwise this.. if want automatically should do
<table class="table"> <thead> <tr ng-repeat="element in elementsheaderbt"> <th>{{ element.cd }}</th> <th>{{ element.cuadro }}</th> <th>{{ element.salida }}</th> <th>{{ element.type }}</th> <th>{{ element.element }}</th> </tr> </thead> <tbody> <tr ng-repeat="element in elementsdataatmt"> <td>{{ element.cd }}</td> <td>{{ element.cuadro }}</td> <td>{{ element.salida }}</td> <td>{{ element.type }}</td> <td>{{ element.element }}</td> </tr> </tbody> </table>
my json this
{ "atmt": { "header": [{ "transportline": "linea transporte", "station": "estracion", "transformer": "trafo", "park": "parque", "linemt": "linea mt", "section": "tramo", "cd": "cd", "transformercdcm": "trafo cd/cm", "element": "elemento", "type": "tipo" }], "data": [{ "transportline": "", "station": "abrera", "transformer": "", "park": "25", "linemt": "aguas1", "section": "", "cd": "ll...", "transformercdcm": "", "element": "t-1", "type": "dis_man_cd" }] }, "bt": { "header": [{ "cd": "cd", "picture": "cuadro", "departure": "salida", "type": "tipo", "element": "elemento bt" }], "data": [{ "cd": "c100446", "picture": "11", "departure": "01", "type": "", "element": "" }] }
}
and controller this
$scope.elementsheaderatmt = response.atmt.header; $scope.elementsdataatmt = response.atmt.data; $scope.elementsheaderbt = response.bt.header; $scope.elementsdatabt = response.bt.data;
sorry poor english hope clear thanks
if understand idea, iterate on key, value tuple in json. suitable here:
<tr ng-repeat="(key, value) in elementsdataatmt "> <td> {{key}} </td> <td> {{ value }} </td> </tr>
Comments
Post a Comment