2017-05-03 4 views
2

Auf einen Klick auf die Schaltfläche bekomme ich die folgende Antwort von Node JS.Angular js ng-wiederholen dynamische Header, vermeiden Sie eine Spalte

[{ 
     "_id": "590998cca8ac14d0c075282c", 
     "CompID": "0001388D", 
     "CompName": "ONE" 
    }, 
    { 
     "_id": "590998cca8ac14d0c075282qc", 
     "CompID": "0001388D2", 
     "CompName": "TWO" 
    }, 
    { 
     "_id": "590998cca8ac14d0c07528qq2c", 
     "CompID": "0001388D23", 
     "CompName": "Three" 
    } 
] 

ich diese Informationen am Druck mit Angular JS Tabelle ng - wiederholen

Dies ist mein Code

Meine Frage ist, ist es möglich, _id Feld überspringen beim Drucken ??

Dies ist mein Code

<div ng-app="myapp" ng-controller="FirstCtrl"> 

     <table border="1"> 
    <tr> 
    <th ng-repeat="(key, val) in collectioninfo[0]">{{ key }}</th> 
    </tr> 
    <tr ng-repeat="row in collectioninfo"> 
    <td ng-repeat="column in row"> 
     {{ column }} 
    </td> 
    </tr> 
</table> 
</div> 

JSFiddle

Antwort

4

Sie mit ng-if versuchen können, die einige elments in ng-repeat zu vermeiden.

var myapp = angular.module('myapp', []); 
 
myapp.controller('FirstCtrl', function($scope) { 
 
    $scope.collectioninfo = [{ 
 
     "_id": "590998cca8ac14d0c075282c", 
 
     "CompID": "0001388D", 
 
     "CompName": "ONE" 
 
    }, 
 
    { 
 
     "_id": "590998cca8ac14d0c075282qc", 
 
     "CompID": "0001388D2", 
 
     "CompName": "TWO" 
 
    }, 
 
    { 
 
     "_id": "590998cca8ac14d0c07528qq2c", 
 
     "CompID": "0001388D23", 
 
     "CompName": "Three" 
 
    } 
 
    ] 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
<div ng-app="myapp" ng-controller="FirstCtrl"> 
 

 
    <table border="1"> 
 
    <tr> 
 
     <th ng-repeat="(key, val) in collectioninfo[0]" ng-if="key !== '_id'">{{ key }}</th> 
 
    </tr> 
 
    <tr ng-repeat="row in collectioninfo"> 
 
     <td ng-repeat="(key2, val2) in row" ng-if="key2 !== '_id'"> 
 
     {{ val2 }} 
 
     </td> 
 
    </tr> 
 
    </table> 
 

 

 

 
</div>

+0

Vielen Dank. es funktioniert super. – Pawan

+0

@ Pawan Sie sind willkommen. :) – Pengyy

1

die jsfiddle prüfen here

<table border="1"> 
    <tr> 
    <th ng-repeat="(key, val) in collectioninfo[0]" ng-show="key != '_id'">{{ key }}</th> 
    </tr> 
    <tr ng-repeat="row in collectioninfo"> 
    <td ng-repeat="column in row" ng-hide="column === row._id"> 
     {{ column }} 
    </td> 
    </tr> 
</table> 

ich einen Scheck für den Schlüssel '_id' hinzugefügt haben.

0

, nachdem Sie die Antwort in Ihrem Winkel Controller tun diese:

$scope.datas = []; 
//lines of code 
.then(function success(response) { 
$scope.collectionInfo=response.data.collectionInfo; 
      for(var i=0;i<$scope.collectionInfo.length;i++){ 
       $scope.index=i; 
       $scope.datas.push($scope.collectionInfo[i]); 


      } 
//lines of code 
}); 

Und auf der HTML-Seite wie folgt vorgehen:

<div id="DisplayCollection"> 
<table ng-repeat="x in collectionInfo"> 
    <tr> 
     <th> 
      CompID 
     </th> 
     <th> 
      CompName 
     </th> 
    </tr> 
    <tr ng-repeat="y in x track by $index"> 
     <td>{{y.compID[$index]}}</td> 
     <td>{{y.compName[$index]}}</td> 
    </tr> 

</table> 

Vorausgesetzt, dass Sie die Daten gesendet haben Form eines Arrays: collectionInfo

Verwandte Themen