在多维数组/对象上进行ng-repeat

时间:2014-09-01 20:26:32

标签: javascript arrays json angularjs angularjs-ng-repeat

我从外部网址获取json对象。

$http.get('http://dev-newsbackend.gotpantheon.com/articles')
  .success(function(data, status){

    $scope.articles = data.articles;

    console.log(data.articles);

  }).error(function(err){

       console.log(err);
  })  
})

我得到的json如下:

{
  "articles": [
    {
      "single": {
        "title": "7 Tech Upgrades to the Old-School Science Class"
      }
    },
    {
      "single": {
        "title": "What Will the ALS Association Do With That $100 Million?"
      }
    },
    {
      "single": {
        "title": "President Obama Rocked a Tan Suit, So Twitter Went Nuts"
      }
    }
  ],
  "view": {
    "name": "articles",
    "display": "page",
    "path": "articles",
    "root": "articles",
    "child": "single",
    "pages": 1,
    "page": 0,
    "count": 3,
    "limit": 10
  }
}

但是,当我执行ng-repeat时,虽然元素被多次打印。没有得到价值。

<ion-list  ng-repeat="article in articles">

    <ion-item>Test : {{ single.title }}</ion-item>

</ion-list>

我的开发者控制台屏幕截图:
这就是我为console.log(data.articles);

所得到的

enter image description here

我的浏览器的屏幕截图,其中列表没有标题值:

enter image description here

1 个答案:

答案 0 :(得分:0)

试试这个:

<ion-list  ng-repeat="article in articles">

    <ion-item>Test : {{article.single.title }}</ion-item>

</ion-list>
相关问题