Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数组中的Json列表返回列表值_Json_Angularjs_Ionic Framework - Fatal编程技术网

数组中的Json列表返回列表值

数组中的Json列表返回列表值,json,angularjs,ionic-framework,Json,Angularjs,Ionic Framework,我是爱奥尼亚的新手,我希望能够扩展一个简单的json数据集,以便在数组中包含列表: 我的json文件如下所示: angular.module('starter.services', []) /** A simple example service that returns some data. */ .factory('Bands', function() { var bands = [ {"id": "0", name: 'U2', nationality: 'Iri

我是爱奥尼亚的新手,我希望能够扩展一个简单的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": "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"
        }
    ]
  }
]
因此,我能够使用repeat返回乐队列表,并传递乐队id以显示各个乐队的详细信息

我不想将band页面扩展到它来返回专辑列表详细信息,所以我猜应该是这样的,但是我需要一些帮助来了解如何从特定band 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>

{{band.name}
{{乐队国籍}

{{album.name} {{album.year}


任何能为我指明正确方向的帮助都会很好。

您需要更改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": "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中重复您的观点:

<ion-item ng-repeat="album in band.albums" type="item-text-wrap" >
  <h2>{{album.name}}</h2>
  <p>{{album.year}}</p>
</ion-item>

{{album.name}
{{album.year}


谢谢,这非常有效。这正是我所需要的,现在我觉得这很有意义。