我有以下数组数据,我想使用Angularjs ng-repeat将这些数据放入表中,如下图所示,任何人都可以帮忙吗?
var data=[
{status:"open",year:2014,value:100.00},
{status:"open",year:2015,value:200.00},
{status:"open",year:2016,value:300.00},
{status:"approved",year:2016,value:10.00},
{status:"approved",year:2015,value:20.00},
{status:"approved",year:2016,value:30.00},
{status:"closed",year:2016,value:1.00},
{status:"closed",year:2014,value:3.00},
{status:"closed",year:2013,value:-10.00}
]
答案 0 :(得分:1)
这是带有ng-repeat和数组数据的工作示例...
// Code goes here
var app = angular.module('soApp', []);
app.controller('DemoController', ['$scope', function($scope) {
$scope.data = [
{status:"open",year:2014,value:100.00},
{status:"open",year:2015,value:200.00},
{status:"open",year:2016,value:300.00},
{status:"approved",year:2016,value:10.00},
{status:"approved",year:2015,value:20.00},
{status:"approved",year:2016,value:30.00},
{status:"closed",year:2016,value:1.00},
{status:"closed",year:2014,value:3.00},
{status:"closed",year:2013,value:-10.00}
];
}])
table{border:1px solid #ccc; font-size:12px; width:100%; border-collapse: collapse;}
table td, table th{border:1px solid #ccc; padding:5px;}
<!DOCTYPE html>
<html ng-app="soApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<style type="text/css">
body{font-family:'helvetica', 'arial', sans-serif;}
td,th{padding:0 10px;text-align:left;}
</style>
</head>
<body ng-controller="DemoController">
<table>
<thead>
<tr>
<th>Status</th>
<th>Year</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in data">
<td ng-bind="row.status"></td>
<td ng-bind="row.year"></td>
<td ng-bind="row.value"></td>
</tr>
</tbody>
</table>
</body>
</html>
答案 1 :(得分:0)
欢迎来到Angular!你会经常使用这种模式:
data
附加到控制器中的$scope
ng-repeat="row in data"
属性添加到tr
元素ng-bind="row.status
元素td
醇>