2017-03-07 78 views
1

我想使用ng-repeat顯示數組值,並且我將使用itemid和photoidlist調用getimage函數來獲取圖像url。如何使用AngularJS循環數組值?

我的JSON是:

$scope.productslist = { 
    "json": { 
    "response": { 
     "servicetype": "10", 
     "functiontype": "104", 
     "statuscode": "0", 
     "statusmessage": "Success", 
     "data": [ 
     { 
      "itemid": 247, 
      "isproduct": true, 
      "disable": false, 
      "itemcost": 150, 
      "itemdescription": "prdct", 
      "itemname": "pro1", 
      "itemno": "#1Pro", 
      "itemcategoryid": 158, 
      "itemcategory": "General", 
      "addedby": "buzi by pree" 
     }, 
     { 
      "itemid": 257, 
      "isproduct": true, 
      "disable": false, 
      "itemcost": 150, 
      "itemdescription": "products", 
      "itemname": "pro 2", 
      "itemno": "pro 2", 
      "itemcategoryid": 158, 
      "itemcategory": "General", 
      "photoidlist": [ 
      138 
      ], 
      "addedby": "buzi by pree" 
     }, 
     { 
      "itemid": 259, 
      "isproduct": true, 
      "disable": false, 
      "itemcost": 150, 
      "itemdescription": "descc", 
      "itemname": "pro 1", 
      "itemno": "pro 3", 
      "itemcategoryid": 158, 
      "itemcategory": "General", 
      "photoidlist": [ 
      139, 140 
      ], 
      "addedby": "buzi by pree" 
     }, 
     { 
      "itemid": 262, 
      "isproduct": true, 
      "disable": false, 
      "itemcost": 599, 
      "itemdescription": "fgg", 
      "itemname": "ff", 
      "itemno": "r", 
      "itemcategoryid": 158, 
      "itemcategory": "General", 
      "addedby": "buzi by pree" 
     }, 
     { 
      "itemid": 263, 
      "isproduct": true, 
      "disable": false, 
      "itemcost": 56, 
      "itemdescription": "ffr", 
      "itemname": "rf", 
      "itemno": "fe", 
      "itemcategoryid": 158, 
      "itemcategory": "General", 
      "photoidlist": [ 
      140, 143, 141 
      ], 
      "addedby": "buzi by pree" 
     } 
     ] 
    } 
    } 
}; 

現在我需要使用ng-repeat遍歷數組,並顯示所有與它的特定值的值。

我創建了一個Fiddle

回答

1

你的邏輯是好的,但你想遍歷一個對象,而不是一個數組。我覺得應該是以下情況:

<tr ng-repeat="item in productslist.json.response.data"> 
    ... 
</tr> 

Forked your Fiddle here.