2017-10-06 55 views
0

我在TS文件無法重複使用鍵JSON數組中的離子2

"stocklist": { 
     "1": { 
      "product_name": "Chakli(500gm)", 
      "item_per_bag": "22", 
      "r_rate": "80", 
      "in_stock_qty": "129", 
      "current_requirement": 998, 
      "depreciateStock": -869, 
      "depreciateStockValue": -69520 
     }, 
     "12": { 
      "product_name": "Khaman mix(200gm)", 
      "item_per_bag": "44", 
      "r_rate": "32", 
      "in_stock_qty": "301", 
      "current_requirement": 521, 
      "depreciateStock": -220, 
      "depreciateStockValue": -7040 
     } 
    } 

,我想在HTML文件遍歷JSON數組。

<tr *ngFor="let deficit of deficitStockList;"> 
      <td text-center>{{ deficit.id }}</td> 
      <td>{{ deficit.product_name }}</td> 
      <td>{{ deficit.in_stock_qty }}</td> 
      <td>{{ deficit.current_requirement }}</td> 
      <td>{{ deficit.depreciateStock }}</td> 
     </tr> 

但它顯示錯誤像數組是不可迭代的。

這裏提到的關鍵字在Ionic中沒有用處,但我無法從服務器端刪除它。

感謝,

+0

提到你生成這個JSON自己呢?如果是這樣,你應該把id?(1,12)移動到對象內部。 – Juxture

+0

是的,我已經生成了這個json。但是同樣的json在服務器應用程序中使用,需要密鑰... –

回答

0

數據格式對象更改爲對象的數組,像下面

"stocklist": [ 
    { 
     "product_name": "Chakli(500gm)", 
     "item_per_bag": "22", 
     "r_rate": "80", 
     "in_stock_qty": "129", 
     "current_requirement": 998, 
     "depreciateStock": -869, 
     "depreciateStockValue": -69520 
    }, 
    { 
     "product_name": "Khaman mix(200gm)", 
     "item_per_bag": "44", 
     "r_rate": "32", 
     "in_stock_qty": "301", 
     "current_requirement": 521, 
     "depreciateStock": -220, 
     "depreciateStockValue": -7040 
    } 
] 
+0

您應該嘗試提供問題原因並解釋您的解決方案。 SO不只是分享代碼。 – MKR