ng-repeater not working for JSON

2019-07-24 11:54发布

问题:

here is my JSON

[{"_id":{"$oid":"54357d7f62042c439bfd6279"},"imageType":"Image/jpg","Heading":"Test Heading","Description":"Test Discription","Image":"","created_at":"","infoType":"QuickInfo"},{"_id":{"$oid":"54357eb862042c439bfd627a"},"imageType":"Image/png","Heading":"Test Heading 2","Description":"Test Discription 2","Image":"","created_at":"","infoType":"QuickInfo"}]

my repeater

<ion-list>
  <ion-item ng-repeat="fact in facts track by $index" href="#/app/fact/{{fact._id}}">
    {{fact.Heading}}
  </ion-item>
</ion-list>

Error: It has populated a lot of empty list items.

HELP!!

回答1:

It seems to be working ok.

    $scope.facts=[
    {
        "_id":{"$oid":"54357d7f62042c439bfd6279"},
        "imageType":"Image/jpg",
        "Heading":"Test Heading",
        "Description":"Test Discription",
        "Image":"",
        "created_at":"",
        "infoType":"QuickInfo"
    },
    {
        "_id":{"$oid":"54357eb862042c439bfd627a"},
        "imageType":"Image/png",
        "Heading":"Test Heading 2",
        "Description":"Test Discription 2",
        "Image":"","created_at":"","infoType":"QuickInfo"
    }
];

<ion-list>
  <ion-item ng-repeat="fact in facts track by $index" href="#/app/fact/{{fact._id}}">
    {{fact.Heading}}
  </ion-item>
</ion-list>

EDIT: Also if you get the data back as JSON you can do

$scope.facts=JSON.parse(json_string);