1
我成功地从php服务器使用$ http获取数据。但我不知道如何使用ngRepear以表格形式显示数据,因为所有的数据都在几个不同的项目中。我将把数据的所有对象显示在表格的不同行中。以下显示了我从php服务器获得的数据。Angularjs:ngRepeat列出来自服务器的所有数据
我成功地从php服务器使用$ http获取数据。但我不知道如何使用ngRepear以表格形式显示数据,因为所有的数据都在几个不同的项目中。我将把数据的所有对象显示在表格的不同行中。以下显示了我从php服务器获得的数据。Angularjs:ngRepeat列出来自服务器的所有数据
下面的代码一瞥可以给你的想法
$scope.retrievedData = [];
//retrieve data from your server
//take the data into above scope variable
<table>
<tr ng-repeat = "data in retrievedData">
<td>data.AssetDescription</td>
<td>data.AssetNumber</td>
<td>data.ComputerName</td>
</tr>
</table>
您需要添加数据到控制器变量:
控制器
function YourController($scope, $http) {
$scope.tableData = [];
$http.get('url').then(function(result) {
$scope.tableData = result.data;
});
}
模板
<table>
<thead>
<tr>
<th>Description</th>
<th>Computer name</th>
<th>Borrow date</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in tableData ">
<td>{{row.data.AssetDescription}}</td>
<td>{{row.data.ComputerName}}</td>
<td>{{row.data.borrowDate}}</td>
</tr>
</tbody>
</table>
这个数据添加到在控制器中一个范围变量,然后在视图中使用ngrepeat显示 –