我是离子的新手,我希望能够扩展一个简单的json数据集,以包含数组中的列表: 我的json文件如下所示:
angular.module('starter.services', [])
/** A simple example service that returns some data. */
.factory('Bands', function() {
var bands = [
{"id": "0", name: 'U2', nationality: 'Irish', category: 'Rock', pic: "U2.jpg", url:"www.u2.com" },
{
"albums":
{"album"
[
{ "id": "101", name:"Songs Of Innocence", year:"2014", pic: "u2_soi_cover.jpg" },
{ "id": "102", name:"No Line On The Horizon", year:"2009", pic: "u2_nloth_cover.jpg" },
{ "id": "103", name:"How To Dismantle An Atomic Bomb", year:"2004", pic: "u2_htdaab_cover.jpg" },
]
},
},
{"id": "1", name: 'Silverchair', nationality: 'Australian', category: 'Grunge', pic: "silverchair.jpg", url:"www.silverchair.com/" },
{
"albums":
{"album"
[
{ "id": "102", name:"Frogstomp", year:"1995", pic: "sc_frogstomp_cover.jpg" },
]
},
},
];
return {
all: function() {
return bandss;
},
get: function(bandId) {
// Simple index lookup
return bands[bandId];
}
}
})
所以我已经能够使用重复返回乐队列表并传递乐队ID以显示各个乐队的详细信息。
我想不要将乐队页面扩展到它以返回专辑列表的详细信息,所以我猜测它会是这样的,但是我需要一些帮助来理解如何从列表中获取列表特定乐队ID。
<ion-content>
<div class="details">
<img src="pics/bands/{{band.pic }}" />
<h2>{{band.name}}</h2>
<p>{{band.nationality}}</p>
</div>
<ion-list>
<ion-item ng-repeat="album in albums" type="item-text-wrap" >
<h2>{{album.name}}</h2>
<p>{{album.year}}</p>
</ion-item>
</ion-list>
</ion-content>
任何帮助我指明正确方向的帮助都会很棒。
答案 0 :(得分:1)
您需要更改json格式,移动&#34;相册&#34;进入&#34;乐队&#34;,像这样:
[
{
"id": "0",
"name": "U2",
"nationality": "Irish",
"category": "Rock",
"pic": "U2.jpg",
"url": "www.u2.com",
"albums": [
{
"id"": "101",
"name": "SongsOfInnocence",
"year": "2014",
"pic": "u2_soi_cover.jpg"
}
]
}
]
现在在你的观点的ng-repeat中:
<ion-item ng-repeat="album in band.albums" type="item-text-wrap" >
<h2>{{album.name}}</h2>
<p>{{album.year}}</p>
</ion-item>