Angularjs基于数组循环记录

时间:2018-04-12 16:17:01

标签: angularjs

我正在使用Angular js

点击之后我得到了响应以下响应如何循环

一个div名称然后像我想要循环的值

我的回复

{  
   "my2":[  
      {  
         "id":5,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-01 00:00:00",
         "updated_at":"2018-04-11 00:00:00",
         "time":"04:32 PM",
         "status":"D"
      },
      {  
         "id":4,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-02 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"12:10 PM",
         "status":"P"
      },
   ],
   "my":[  
      {  
         "id":44,
         "cuid":21,
         "name":"my",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:08 PM",
         "status":"P"
      }
   ],
   "Testing":[  
      {  
         "id":43,
         "cuid":19,
         "name":"Testing",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:05 PM",
         "status":"P"
      }
   ]
}

我试试这个

<div ng-repeat="data in reports" class="all_report">



           <div ng-repeat="data in reports">
{{reports.indexOf(data)}}
</div>
                <!--<div class="date">
                    {{data.created_at}} <br/>
                <span class="month">{{data.created_at}}</span>
                </div>
                <div class="status">{{data.status}}</div>-->
            </div>

但它没有打印任何如何以div格式打印

我不知道如何打印

我上面试过但没打印

如何实现这个以ng-repet打印?

2 个答案:

答案 0 :(得分:1)

您可以使用 来迭代 对象中的键值对。对于您的具体情况,HTML将类似于以下内容:

List<String> result = list.stream().distinct().sorted((a1,a2)->{
        return Integer.compare(Integer.parseInt(a1.split("-")[1]), Integer.parseInt(a2.split("-")[1]));
    }).collect(Collectors.toList());

答案 1 :(得分:0)

看起来我可以帮助您解决问题,但是如果您写下您期望从JSON看到的答案,以便能够容纳HTML,那么会更好,但请查看{{1使用ng-repeat可以帮助您导航angularJS,但只要您构建好JSON,它就会适合JSON,如果它真的很适合div你需要什么。 我留下了一个你可以支持的链接

https://jptacek.com/2013/10/angularjs-introducing-ng-repeat/

$scope.test = {
   "my2":[
      {
         "id":5,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-01 00:00:00",
         "updated_at":"2018-04-11 00:00:00",
         "time":"04:32 PM",
         "status":"D"
      },
      {
         "id":4,
         "cuid":20,
         "name":"my2",
         "month":"04",
         "created_at":"2018-04-02 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"12:10 PM",
         "status":"P"
      },
   ],
   "my":[
      {
         "id":44,
         "cuid":21,
         "name":"my",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:08 PM",
         "status":"P"
      }
   ],
   "Testing":[
      {
         "id":43,
         "cuid":19,
         "name":"Testing",
         "month":"04",
         "created_at":"2018-04-12 00:00:00",
         "updated_at":"2018-04-12 00:00:00",
         "time":"09:05 PM",
         "status":"P"
      }
   ]
}

在HTML中,类似的东西可以......

    <div ng-repeat="data in test" class="all_report">
            <div ng-repeat="x in data">
                    {{x}}
            </div>
     </div>