在angular中,使用ng-repeat循環(huán)輸出一個(gè)列表,然後需要獲取每個(gè)循環(huán)節(jié)當(dāng)中具體的一個(gè)參數(shù)值(是數(shù)值),然後整個(gè)循環(huán)節(jié)的值總數(shù)相加,具體代碼如下:
<li class="opt" ng-repeat="num in data.vote_options track by num.option_id" ng-class="{'finished':'num.is_voted==1','':'num.is_voted==2'}">
<input class="magic-checkbox" type="checkbox" name="{{num.option}}" id="{{num.option_id}}" ng-checked>
<label for="{{num.option_id}}">
<p class="right" ng-bind=num.option>Normal</p>
<p class="progress">
<p class="progress-bar" style="width: 55%; background:#a2d346;"></p>
<span ng-bind="num.voted_num / (num.length).voted_num">55%</span>
<p class="votesnums"><i ng-bind="num.voted_num"></i>票</p>
</p>
</label>
</li>
紅圈中的55%是根據(jù)上述程式碼中的(選項(xiàng)票數(shù)/總票數(shù)num.voted_num/num.length.voted_num)這樣做法渲染出來(lái)的效果結(jié)果是NaN,請(qǐng)問大神們,知道怎麼去獲取總的循環(huán)節(jié)中的具體某個(gè)參數(shù)值的總和啊?
閉關(guān)修行中......
總票數(shù)是要後臺(tái)資料傳給你,或是自己js裡面循環(huán)計(jì)算一下。在ng-repeat裡面是沒辦法計(jì)算的