来自 *.JSON 文件的 Angular.js ng-repeat 列表 [英] Angular.js ng-repeat list from *.JSON file

查看:27
本文介绍了来自 *.JSON 文件的 Angular.js ng-repeat 列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始学习 Angular.js,但遇到了第一个小问题.

I begin learning Angular.js and I have first little problem.

这是我的 hello.js 文件:

function Hello($scope, $http) {
  $http.get('URL').
  success(function(data) {
  $scope.response = data
 });}

响应是我需要解析的 *.json 文件.JSON 的样子:

The response is a *.json file that I need to parse. JSON looks in a way:

"data":[{
   "status":"true",
   "name":"blabla"
},{
   "status":"true",
   "name":"blabla2"
}]

index.html 文件中,我有 <div ng-controller="Hello"> 我想在其中列出所有 JSON 的状态和名称领域.

In index.html file I have <div ng-controller="Hello"> where I would like to make a list of all JSON's status and name fields.

我不知道如何使用 ng-repeat 来制作 *.json 文件中所有组件的列表.你可以帮帮我吗?:)

I have no idea how could I use ng-repeat in order to make a list of all components from *.json file. Could you help me? :)

干杯,

卢克

推荐答案

如果我正确理解了您的问题,并且您希望保持控制器原样,您应该执行以下操作:

If I understood your question properly, and you want to keep your controller as it is, you should do something like:

HTML:

<ul>
    <li ng-repeat="resp in response.data"> 
        My Status: {{resp.status}} and my Name: {{resp.name}}
    </li>
</ul>

希望我有所帮助.

这篇关于来自 *.JSON 文件的 Angular.js ng-repeat 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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