如何从angularjs中的两个json文件中获取值

时间:2015-10-08 05:06:11

标签: json angularjs

任何人都可以帮助解决我的问题。

角度js中的

我有json和HTML文件

test.json

{
"list": [
{
    "id": 1,
    "Name": "Name 1"
},
{
    "id": 2,
    "Name": "Name 2"
}
]
}

array.json

{
    "list": [
    {
        "id": 1,
        "time": [
        {
            "time1": "10.00am",
            "time2": "10.10am",
            "time3": "10.20am",
            "time4": "10.30am"
        }
        ]
    }

我需要输出如下

id: 1
Name: Name1
time: 10.00am, 10.10am, 10.20am, 10.30am

id: 1
Name: Name1
time: 10.00am, 10.10am

先谢谢

2 个答案:

答案 0 :(得分:0)

HTML

<div class="abc" ng-repeat="data in datas[0].list">
    ID:{{data.id}}<br>
    Name:{{data.Name}}<br>
    Time:
        <ANY ng-repeat="times in data.time[0]">
            {{times}}
        </ANY>
    <hr>
</div>

控制器

$scope.datas=[{
"list": [
{
    "id": 1,
    "Name": "Name 1",
    "time": [
    {
        "time1": "10.00am",
        "time2": "10.10am",
        "time3": "10.20am",
        "time4": "10.30am"
    }
    ]
},
{
    "id": 2,
    "Name": "Name 2",
    "time": [
    {
        "time1": "10.00am",
        "time2": "10.10am"
    }
    ]
}
]
}];

答案 1 :(得分:0)

你可以在你的情况下使用ng-repeat链接。

 <span ng-repeat="list in myList">
  Id : {{list.id}}<br/>
  Name : {{list.Name}}<br/>
    <span ng-repeat="tm in times | filter:{id: list.id}">
      Time : <span ng-repeat="tim in tm.time">
      <span ng-repeat="t in tim">
        {{t}}{{$last ? '' : ', '}}
        <span>
      </span>    
    </span><br/>
  </span>

这是适合你的工作笔。

Codepen