平均有angularjs我收到這樣的JSON響應:計算嵌套JSON
{
"productDesc": "Other posterior corneal dystrophies",
"ProductId": 1,
"productName": "Keylex",
"productPrice": 3529.24,
"productStatus": false,
"productStock": 23,
"productModifyDate": "2016-10-13T20:13:12",
"productUrl": "http://dummyimage.com/153x172.jpg/5fa2dd/ffffff",
"ReviewProducts": [
{
"ratingReview": 8.2,
"reviewDesc": "aaaaa",
"ReviewProductIdNumber": 1,
"User": {
"username": "hsullivan0",
"UserId": 1,
"name": "Heather",
"lastName": "Sullivan"
}
},
{
"ratingReview": 6.8,
"reviewDesc": "mattis pulvinar nulla pede ullamcorper augue a suscipit nulla elit ac nulla sed",
"ReviewProductIdNumber": 2,
"User": {
"username": "jcarrod",
"UserId": 878,
"name": "Jessica",
"lastName": "Carr"
}
}
]
}
我想要做的就是從每個產品計算平均ratingReview並顯示它,現在我的HTML如下:
<div class="col-sm-4 col-lg-4 col-md-4" ng-repeat="x in product | limitTo:30">
<div class="thumbnail">
<img ng-src="{{x.productUrl}}" alt="">
<div class="caption">
<h4 class="pull-right">{{x.productPrice | currency}}</h4>
<h4>
<a href="#">{{x.productName}}</a>
</h4>
<p>{{x.productDesc}}.</p>
</div>
<div class="ratings" ng-repeat="review in x.ReviewProducts">
<p class="pull-right">{{review.ratingReview}}</p>
<p>
<span class="glyphicon glyphicon-star"></span>
</p>
</div>
</div>
</div>
BTW不是所有的產品都具有審覈評分等等的情況下,是空洞的表演沒什麼
您可能要在將其發送到前端之前計算平均值。來自服務器的消息將隨附在標題中,然後是產品列表。 –
因爲您使用重複,它會重複所有審查和顯示像這樣 – Akashii