javascript - 在 AngularJS ng-repeat 中处理 json 数据

标签 javascript angularjs json

我想使用 AngularJS ng-repeat 在表中显示 json 数据,但是我的表的第一行仍然是空的,因为我没有访问第一行的 json 数据。我想省略第一行的 json 数据 table 。如何做到这一点?

我的 json 格式:

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

myApp.controller('MyCtrl', function($scope) {
    $scope.list = [
    {"dept_id":"d10","dname":"dname"},

    {"eid":"10","ename":"nam1"},

    {"eid":"20","ename":"nam2"},

    {"eid":"30","ename":"nam3"},

    {"eid":"40","ename":"nam4"}
    ];


$scope.list1 = [

    {"eid":"10","ename":"nam1"},

    {"eid":"20","ename":"nam2"},

    {"eid":"30","ename":"nam3"},

    {"eid":"40","ename":"nam4"}
    ];
});
<html>
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
    <script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
  

</head>

<div class="container">

<div ng-app="myApp" ng-controller="MyCtrl">



<table class="table table-striped table-bordered">
    <thead>
      <tr>
	 <th>Sr</th>

<th>Employee ID</th>
	 <th>name</th>
 
    </tr>    
   </thead>
    <tbody>
  
   <tr ng-repeat="data in list">
      <td> {{$index+1 }} </td>
     
     <td> {{ data.eid }} </td>
      <td> {{ data.ename }} </td>
        
  </tr>
</tbody>
  
</table>

    But I want like this :


<table class="table table-striped table-bordered">
    <thead>
      <tr>
	 <th>Sr</th>

<th>Employee ID</th>
	 <th>name</th>
 
    </tr>    
   </thead>
    <tbody>
  
   <tr ng-repeat="data in list1">
      <td> {{$index+1 }} </td>
     
     <td> {{ data.eid }} </td>
      <td> {{ data.ename }} </td>
        
  </tr>
</tbody>
  
</table>
</div>


</div>

最佳答案

尝试像这样使用 ng-if

 <tr ng-repeat="data in list1" ng-if="$index > 0">
          <td> {{$index+1 }} </td>

         <td> {{ data.eid }} </td>
          <td> {{ data.ename }} </td>

      </tr>

关于javascript - 在 AngularJS ng-repeat 中处理 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44286694/

相关文章:

javascript - AngularJS : Adding variable into a chain of promises

javascript - ng-click 在 AngularJS 中不触发,而 onclick 却触发

php - 在打印之前检查 file_get_contents 返回

javascript - 需要一些使用 JQuery 解析 JSON 的帮助

javascript - Mootools:获取被点击的元素值

javascript - angularjs教程代码调试

javascript - Firebase 中未找到 if 语句变量 == null?

javascript - 如何将 JS 对象作为 JSON 正确发送?

javascript - 我如何使用框内的 jQuery 使具有类 fm 然后 sm 的行一个接一个地出现?

javascript - 无法访问 Angular 2 组件中 addEventListener() 中的 'this' 上下文