2017-04-12 17 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"> 
相關問題