从*以.json文件Angular.js NG-重复列表 [英] Angular.js ng-repeat list from *.JSON file

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

问题描述

我开始学习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 文件我有< D​​IV NG控制器=你好> 在这里我想作一个列表所有的JSON的地位和name字段。

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.

我不知道我怎么会为了让从*以.json文件中的所有组件的列表中使用 NG-重复。你可以帮帮我吗? :)

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

希望我一直有帮助。

Hope I've been helpfull.

这篇关于从*以.json文件Angular.js NG-重复列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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