【发布时间】:2015-05-24 03:10:54
【问题描述】:
我在使用 Angular 进行 ng-repeat 时遇到了困难。
我的 JSON 数据如下所示
{
"shows": {
"stations": {
"balaton": [{
"name": "Minimal",
"artist": "Sven Tasnadi",
"duration" : "1H"
}, {
"name": "Forest of Love",
"artist": "Bas Ibelini",
"duration" : "2H"
}, {
"name": "Sound of Underground",
"artist": "Potential Badboy",
"duration" : "2H30"
}],
"djradio": [{
"name": "Strickly Electronica",
"artist": "Culptrate",
"duration" : "1H"
}, {
"name": "Sound of Underground",
"artist": "Potential Badboy",
"duration" : "2H"
}, {
"name": "Sound Time",
"artist": "Leona Graham",
"duration" : "2H30"
}]
}
}
}
在我的控制器中,我将对象设置为范围。
$http.get('json/show-schedule.json').success(function(res){
$scope.schedule = res.shows.stations;
});
在我的 HTML 中,
<div class="schedule-station" ng-repeat="item in schedule">
<div class="schedule-station-logo" style="background-image:url('img/stations/{{balaton}}.png')"></div>
<ul>
<li class="schedule-duration-{{item.duration}}">
<span class="schedule-time">11PM</span>
<span>{{item.name}}</span>
<i><span>{{item.artist}}</span></i>
</li>
</ul>
</div>
基本上,我有一个 DIV,需要根据 JSON 中有多少站来创建。然后,我需要获取电台名称,即“Balaton”和“DJRADIO”,这应该放在我的背景图像中,例如balaton.png。
然后,应根据该特定站点中的轨道数重复列表项。
我很难弄清楚如何做到这一点,而且我的尝试显然还有很长的路要走。
【问题讨论】:
标签: angularjs