2016-12-12 17 views
0

我需要使用ng-repeat在產品AL200W401(不含xxxx)中顯示密鑰。在我的HTML代碼中顯示AL200W401xxxx。如何去感謝這個。Angular顯示ng-repeat鍵

JSON

{ 
    "kits":"B11D0W201,AL200W401", 
    "dateTo":"13/12/2016", 
    "orders":[ 
     { 
      "AL200W401":1, 
      "B11D0W201":0, 
      "date":"13 Dec 16" 
     } 
    ], 
    "dateFrom":"12/12/2016", 
    "products":[ 
    { 
     "AL200W401":"AL200W401xxxx", 
     "B11D0W201":"B11D0W201xxxx" 
    } 
    ] 
} 

HTML

<th ng-repeat="column in products">{{column}}</th> 

回答

2

有一種情況的解決方案是設其他類似的問題。檢查this例如

所以,你可以這樣來做:

<th ng-repeat="(key,value) in products[0]">{{key}}</th> 

請檢查該工作演示:https://jsfiddle.net/hd84335/j0dr7bbp/

+0

謝謝這對我有用。我已經投票了。 – June

1
<th ng-repeat="(key,value) in products[0]">{{key}}</th> 
1

工作演示:

var myApp = angular.module('myApp',[]); 
 

 
myApp.controller('MyCtrl',function ($scope) { 
 
    $scope.jsonObj = { 
 
    "kits":"B11D0W201,AL200W401", 
 
    "dateTo":"13/12/2016", 
 
    "orders":[ 
 
     { 
 
      "AL200W401":1, 
 
      "B11D0W201":0, 
 
      "date":"13 Dec 16" 
 
     } 
 
    ], 
 
    "dateFrom":"12/12/2016", 
 
    "products":[ 
 
    { 
 
     "AL200W401":"AL200W401xxxx", 
 
     "B11D0W201":"B11D0W201xxxx" 
 
    } 
 
    ] 
 
}; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="MyCtrl"> 
 
<div ng-repeat="(key,value) in jsonObj.products[0]">{{key}}</div> 
 
</div>

+0

謝謝Rohit,這當然也可以工作,謝謝你的例子。儘管我只能提供一個答案。 – June

+0

@June沒問題! :) –