我的產品清單作爲JSON對象計算總價值動態的角度
[
{
"id": 22565423428,
"title": "SV 8GB USB Flash Memory E100",
"imageUrl": "/images/22565423428.png",
"url": "/products/22565423428",
"prices": [
{
"amount": 159.92,
"currency": "SEK"
}
]
},
{
"id": 22565423394,
"title": "Litware Wireless Mouse M35",
"imageUrl": "/images/22565423394.png",
"url": "/products/22565423394",
"prices": [
{
"amount": 239.6,
"currency": "SEK"
}
]
}
]
,這是我的NG-重複代碼,當用戶更改數量
<ul>
<li class="basket-item" ng-repeat="product in products">
<div class="product-item-image">
<img src={{product.imageUrl}} />
</div>
<div class="product-item-description">
<h2><a href="product.html">{{product.title}}</a></h2>
<a href="#">Description</a>
</div>
<div class="product-item-qtn">
<input type="number" name=quantity ng-model="quantity" ng-init="quantity = 0"> st
<p><b>quantiy</b>1-3</p>
</div>
<p class="product-item-price">x {{product.prices[0].amount}} {{product.prices[0].currency}}</p>
<p class="product-item-total" >{{product.prices[0].amount * quantity}}</p>
</li>
</ul>
總量是可變的。
有什麼方法可以動態地獲得所有產品的總金額?
<span>{{totalAmount}}</span>
謝謝您的回答。它確實節省了我 – shinta