角度js中的动态数据表

时间:2018-01-04 12:23:46

标签: javascript jquery html angularjs

我想在角度js中创建一个动态数据表,其中第一列带有复选框。数据将采用Json格式,如下所示,

$scope.items = [
        { "id": "1", "lastName": "Test1", "firstName": "Test", "email": "test1@example.com" },
        { "id": "2", "lastName": "Test2", "firstName": "Test", "email": "test2@example.com" },
        { "id": "3", "lastName": "Test3", "firstName": "Test", "email": "test3@example.com" },
        { "id": "4", "lastName": "Test4", "firstName": "Test", "email": "test4@example.com" },
        { "id": "5", "lastName": "Test5", "firstName": "Test", "email": "test5@example.com" }
    ];

id将是一个带复选框的列,所有其他列都将包含数据。 表格的标题也是动态的,列也是如此。

1 个答案:

答案 0 :(得分:0)

如果列是动态的

<table style="width:100%">
  <tr ng-repeat="item in items | limitTo:1">
   <th ng-repeat="(key,value) in item">{{key}}</th>
   <td  ng-repeat="(key,value) in item">
    <div ng-show="key == 'id'">
     <input type="checkbox" value={{value}} name="id" />
    </div>
    <div ng-show="key != 'id'">
     {{value}}
    </div>
   </td>
  </tr>
 </table>

ng-repeat对密钥执行JSON排序,要首先获取ID,请跳过JSON排序Skip JSON ordering(因为在跳过JSON排序后,您的JSON首先具有ID,因此您将首先获得ID)

相关问题