ng-repeater不适用于JSON [英] ng-repeater not working for JSON

查看:145
本文介绍了ng-repeater不适用于JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的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 !!

推荐答案

看起来工作正常。

    $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:
此外,如果您以JSON格式返回数据, / p>

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

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

这篇关于ng-repeater不适用于JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆