一切正常,但是当没有其他数据时,我会得到额外的5行空数据:
示例:
Sat, Apr 25 2015 Madison Square Garden, New York, New York, USA Wladimir Klitschko 63 vs Bryant Jennings 19 vs vs vs vs vs Sat, May 09 2015 Minute Maid Park, Houston, Texas, USA James Kirkland 32 vs Saul Alvarez 44 vs vs vs vs vs
我的JS:
function WidgetCtrl($scope, $http) {
$scope.items = [];
$http.jsonp("http:/domain.com/schedule?callback=JSON_CALLBACK").success(function(data)
{
$scope.items = data;
}).error(function(data, status, headers, config) {
$scope.status = status;
});
}
的index.html
<div id="widget-content" ng-controller="WidgetCtrl">
<div ng-repeat="item in items">
{{item.searchdate}} {{item.event_place}}
<div class="widget-list">
<div ng-repeat="name in item">
{{name.boxer1_name}} {{name.boxer1_w}} vs {{name.boxer2_name}} {{name.boxer2_w}}
</div>
</div>
</div>
</div>
JSON:
[
{
"event_id":"1821",
"searchdate":"Sat, Apr 25 2015",
"event_place":"Madison Square Garden, New York, New York, USA",
"networks":"TV: HBO Boxing",
"time":"Time: 9pm Et",
"0":{
"match_id":"5068",
"match_name":"Heavyweight",
"mainevent":"main",
"body":"",
"boxer1_id":"7",
"boxer1_name":"Wladimir Klitschko",
"boxer1_w":"63",
"boxer1_l":"3",
"boxer1_d":"0",
"boxer1_ko":"53",
"boxer2_id":"2780",
"boxer2_name":"Bryant Jennings",
"boxer2_w":"19",
"boxer2_l":"0",
"boxer2_d":"0",
"boxer2_ko":"10"
}
},
{
"event_id":"1853",
"searchdate":"Sat, May 09 2015",
"event_place":"Minute Maid Park, Houston, Texas, USA",
"networks":"TV: HBO",
"time":"Time: 9pm ET",
"0":{
"match_id":"5127",
"match_name":"super welterweight",
"mainevent":"main",
"body":"",
"boxer1_id":"233",
"boxer1_name":"James Kirkland",
"boxer1_w":"32",
"boxer1_l":"1",
"boxer1_d":"0",
"boxer1_ko":"28",
"boxer2_id":"1336",
"boxer2_name":"Saul Alvarez",
"boxer2_w":"44",
"boxer2_l":"1",
"boxer2_d":"1",
"boxer2_ko":"31"
}
}
]
答案 0 :(得分:0)
我认为问题是你的第二个ng-repeat中的“item in item”。它只是通过6个数据(event_id,searchdate等),并且唯一一个找到拳击手数据的是名为“0”的项目。根据您的数据,您应该使用
<ng-repeat="name in item.0">
因为你的拳击手数据包含在item.o而不是item中。
答案 1 :(得分:0)
三天后我解决了问题。我从&#34; 0&#34;更改了我的JSON Feed到&#34;匹配&#34;。谢谢斯科特。不知何故,你的回答帮助我解决了这个问题。