使用wxs,写在wxml最上边
<wxs module=“test”>
sum = 0
T = {
add : function(n){
sum += parseFloat(n)
},
getSum : function(){
a = sum
sum = 0
return a == 0 ? ‘0.00’ : a
}
}
module.exports = T
</wxs>
使用
<view wx:for="{{two.tranGroupDet}}" wx:for-item=“three” wx:key=“id”>
{{test.add(three.discountAmount)}}
<view class=“table shuye”>
…
</view>
<view wx:if="{{index+1==two.tranGroupDet.length}}">合计:{{test.getSum()}}</view>
</view>