2017-04-21 5 views
0

Ich bin ganz neu in Angular, und ich habe hier bekommen verwaltet:Wie render ich spezifische Daten mit eckigen?

<tr ng-repeat="spec in res"> 
    <td> {{$index + 1}} </td> 
    <td>{{ spec }}</td>    
</tr> 

Derzeit meine Ausgabe ist:

[["suite1",{"id":"suite1","description":"test cases","fullName":"my cases","failedExpectations":[],"status":"finished","specs":[{"id":"spec0","description":"should be able to add an unit","fullName":"etc cases","failedExpectations":[],"passedExpectations":[],"pendingReason":"","status":"passed"}]},"timestamp: Thu Apr 20 2017 09:47:38 GMT+0300 (EEST)"]] 

Wie kann ich ein bestimmtes Feld angezeigt werden? ..? (Zum Beispiel die ID oder die Beschreibung oder der vollständige Name

Edit: Ich verwende Angular 1.6.3

EDIT2.

json Ergebnis

<pre>{{ res | json }}</pre> 

Ergebnis hier

ich habe auch eine kleine Funktion erstellt, die das Array in ein Objekt übersetzt:

function toObject(arr) { 
     let rv = {}; 
     for (let i = 0; i < arr.length; ++i) 
      if (arr[i] !== undefined) rv[i] = arr[i]; 
     return rv; 
     } 

    console.log(toObject(events)); 
    $scope.res = toObject(events); 

oder

$scope.res = toObject(events); 

machte keinen Unterschied

Dies, um die Daten zu übersetzen, in diese:

Object {0: "[["suite1",{"id":"suite1","description":"RW - rate…tamp: Fri Apr 21 2017 11:45:06 GMT+0300 (EEST)"]]", 1: "[["suite1",{"id":"suite1","description":"rates","f…tamp: Fri Apr 21 2017 11:45:55 GMT+0300 (EEST)"]]", 2: "[["suite1",{"id":"suite1","description":"rates","f…tamp: Fri Apr 21 2017 11:46:12 GMT+0300 (EEST)"]]"} 

Antwort

1

enter image description here Hier ist die Lösung für sie Jsfiddle link

updated jsfiddle link

J S-Code

var app = angular.module('myApp', []); 

    app.controller('ctrl', function($scope) { 
    $scope.res = [ 
     ["suite1", { 
     "id": "suite1", 
     "description": "test cases", 
     "fullName": "my cases", 
     "failedExpectations": [], 
     "status": "finished", 
     "specs": [{ 
      "id": "spec0", 
      "description": "should be able to add an unit", 
      "fullName": "etc cases", 
      "failedExpectations": [], 
      "passedExpectations": [], 
      "pendingReason": "", 
      "status": "passed" 
     }] 
     }, "timestamp: Thu Apr 20 2017 09:47:38 GMT+0300 (EEST)"] 
    ]; 
    }); 

HTML

<div ng-app='myApp' ng-controller='ctrl'> 
    <table border='1'> 
     <tr> 
     <th> 
      ID 
     </th> 
     <th>Full Name 
     </th> 
     </tr> 
     <tr ng-repeat="spec in res"> 
     <td> {{$index + 1}} </td> 
     <td>{{ spec[1].fullName }}</td> 
     </tr> 

    </table> 
    </div> 

hoffe, dies wird Ihnen helfen,

+0

nichts gerendert wird, neben dem Index-Zähler. –

+0

check the picture uploaded –

+0

Ich habe eine extra "in der $ scope.res, siehe editierte json-Ausgabe –

0

da dies ein mehrdimensionales Array ist, dass Sie verwenden müssen verschachtelte ng-Wiederholungen

<table> 

    <tr ng-repeat="spec in res track by $index"> 
    <td> 
    <table> 
     <tr ng-repeat="spe in spec track by $index"> 
     <td>{{ spe.id }}</td>  
     <td>{{ spe.fullName }}</td>    
    </tr> 
    </table> 
    </td>   
</tr> 
</table> 

angular.module("app",[]) 
 
.controller("ctrl",function($scope){ 
 
$scope.res = [["suite1",{"id":"suite1","description":"test cases","fullName":"my cases","failedExpectations":[],"status":"finished","specs":[{"id":"spec0","description":"should be able to add an unit","fullName":"etc cases","failedExpectations":[],"passedExpectations":[],"pendingReason":"","status":"passed"}]},"timestamp: Thu Apr 20 2017 09:47:38 GMT+0300 (EEST)"]] 
 

 

 
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="app" ng-controller="ctrl"> 
 
<table> 
 
    
 
    <tr ng-repeat="spec in res"> 
 
    <td> 
 
    <table> 
 
     <tr ng-repeat="spe in spec"> 
 
     <td>{{ spe.id }}</td>  
 
     <td>{{ spe.fullName }}</td>    
 
    </tr> 
 
    </table> 
 
    </td>   
 
</tr> 
 
</table> 
 
</div>

+0

nichts wird mit dem genannten Code gemacht –

+0

die Demo zu sehen !!! –

+0

Fehler: [ngRepeat: Duples] Duplikate in einem Repeater sind nicht erlaubt. Verwenden Sie den Ausdruck "Track by", um eindeutige Schlüssel anzugeben. Repeater: spe in spec, Duplizieren Schlüssel: string: [, Doppelter Wert: [ –

0
<tr ng-repeat="spec in res"> 
<td>{{:: $index + 1}} </td> 
<td>{{:: spec }}</td> 
<td>{{:: spec.ID }}</td>    
<td>{{::spec.fullName }}</td>       

+0

der Index-Zähler und die Spezifikation wird gerendert (genau wie oben beispielhaft dargestellt. Die ID und der FullName nicht. –