嗨,我是 AngularJS 的新手。尝试与 JSON API 通信。该 API 被称为我正在获取结果位,但结果未填充到视图中。
这是视图:
<div >
<div data-ng-repeat="order in ordersResult.orders">
{{error}}
<fieldset class="fieldset">
<legend>
<b>{{order.klant.straat}} {{order.klant.huisnummer}} - {{order.klant.bedrijf}}</b>
</legend>
<table class="table table-bordered table-striped table-hover">
<th>Broodje</th><th>Aantal</th>
<tr data-ng-repeat="(tag,aantal) in order.broodjes" data-ng-click="check()">
<td>{{tag}}</td><td>{{aantal}}x</td>
</tr>
<tr data-ng-repeat="(tag,opmerkingen) in order.broodjesSpeciaal">
<td>{{tag}}</td><td><span ng-repeat="opmerking in opmerkingen">1x {{opmerking}}<br></span></td>
</tr>
</table>
</fieldset>
</div>
</div>
这是控制器:
app.controller('BezorgController', function ($scope, $resource) {
function getToday(){
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm}
//return mm+""+dd+""+yyyy;
return "22052013";
}
$scope.ordersRequest = $resource('http://www.movieapphd.com/bertus/api.1.0.0/order/bezorging/:day?key=:key',
{day: getToday(), key: API_KEY },
{get: {method: "JSONP"}}
);
$scope.ordersResult = $scope.ordersRequest.get();
if($scope.ordersResult.size == 0){
$scope.error = "Geen bezorgingen vandaag";
}
});
这是我得到的json:
{
"orders":[
{
"klant":{
"bedrijf":"X",
"straat":"Haarlemmer",
"huisnummer":"8"
},
"broodjes":{
"0.0":0
},
"broodjesSpeciaal":{
"0.0":[
"nothing"
]
}
},
{
"klant":{
"bedrijf":"Anouk Beauty Gangbang",
"straat":"Haarlemmer",
"huisnummer":"220"
},
"broodjes":{
"0.0":0,
"1.1":2,
"1.2":1,
"2.3":1
},
"broodjesSpeciaal":{
"0.0":[
"nothing"
]
}
},
{
"klant":{
"bedrijf":"Hans Kazan GoochelTrucs",
"straat":"Haarlemmer",
"huisnummer":"222"
},
"broodjes":{
"0.0":0,
"1.1":2,
"1.2":2,
"2.3":1,
"3.1":1
},
"broodjesSpeciaal":{
"0.0":[
"nothing"
],
"2.3":[
"zonder stukjes",
"met extra stukjes"
]
}
}
]
}
我在这里做错了什么?