我有一个正在处理json数组的项目(以后将来自Web服务)
我正在尝试使用ng-repeat将该数据加载到表中。 (我之前已经做过,这次只是滑贴我所缺少的东西)
我将代码发布到github上:https://github.com/sheets/Sch
我也很乐意在此发布代码:
<body ng-app="MyApp">
<div ng-controller="SchCtrl">
<table class="table table-striped table-bordered">
<thead>
<th width="15%">Date and Time</th>
<th width="50%">Provider</th>
<th width="15%">Location</th>
<th width="10%">Map</th>
</thead>
<tbody>
<tr ng-repeat="appointment in appointments | orderBy:'startDatetime':true">
{{appointments.startDatetime | date:'MM/dd/yyyy HH:mm'}}
{{appointments.providerName}}
{{appointments.apptLocation}}</tr></tbody></table>
</div>
</body>
和app.js:
var app = angular.module("MyApp", []);
app.controller("SchCtrl", function($scope, $http) {
$http.get('/appointments.json').
success(function(data, status, headers, config) {
$scope.appointments = data;
}).
error(function(data, status, headers, config) {
// log error
});
});
最佳答案
您可以看一下this simple exaple
1.您需要将所有数据包装在TD标签中
2.要访问您的数据-您需要像data.appointments
这样操作
3.在ng-repeat
中,您需要访问约会数组中的每个项目-所以是appointment
关于javascript - Angular.js ng-使用json重复数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25649433/