2017-04-12 22 views
1

如何在角度js中使用foreach语句?我目前的数据是以json格式打印出来的。我想把它打印出来。如何在html上使用带有angularjs的foreach

的Html

<p>{{controller.greeting.custinfo}}</p> 

//attempt 
<p ng-repeat= >{{controller.greeting.custinfo}}</p> 

在UI输出

{"id":null,"biling_address":"null","billing_state":"FL","ip_Addresses":["123:111:2101","","NULL"],name":"jimmmy"} 

java的输出

System.out.println(custinfo); 
[email protected] 

我如何使用foreach统计以新行显示数据?而不是JSON格式。

我知道如何与thymeleaf做到这一点,下面的例子

<table th:each="custinfo : ${custinfo}"> 

    <tr> 
     <td ng-show="id" class="padded">id:</td> 
     <td ng-show="id" th:text="${custinfo.id}" class="padded"></td> 
    </tr> 
    //continue down 

回答

2

只是环通吧:

<p ng-repeat="(key, value) in controller.greeting.custinfo">{{key}}: {{value}}</p> 
+0

对我来说,这将是键/值? –

+0

第一行:'key =“id”'&'value =“null”'。 – lin

+0

好的,关键会工作,但不值。每次更改值。所以我不能只设置值 –

0

试试这个:

<p ng-repeat="(key, value) in yourObj">{{yourObj[key]}}</p>

如果我明白你想做什么。

0

要使用AngularJS显示列表,您需要一个将迭代的数组。

比方说,你有客户

$scope.customers = [{id:1, name:'customer1'}, .....]; 

你会做的列表,以便该

<ul> 
<li ng-repeat="custInfo in customers">{{custInfo.name}}  </li> 
</ul> 
0

AngularJS可以遍历对象与ng-repeat

$scope.data = {"id":null,"biling_address":"null","billing_state":"FL","ip_Addresses":["123:111:2101","","NULL"],"name":"jimmmy"}; 

<table> 
    <tr ng-repeat="(key, value) in data"> 
    <td>{{key}}</td> 
    <td class="padded">{{value}}</td> 
    </tr> 
</table> 

实例为您的数据: https://jsfiddle.net/fn8rqjz2/1/

如果要显示或隐藏基于id元素:

<tr ng-show="data.id" ng-repeat="(key, value) in data"> 
相关问题