微信小程序的wxml页面里怎样调用函数来处理相关数据呢? wxs

需求:

在后端返回的数据里面,有个 orderPrice 字段。

orderPrice:1500   现在想在页面上显示的是15.00。返回的数据很多,只能在wx:for循环里面做处理。

解决办法:

这里我们需要使用wxs来完成。具体详见官方文档

代码:

test.wxml页面

<!-- 用户处理页面数据,保留两位小数点 -->
  <wxs module="m1">
     var toFixedFn = function(price) {
    return Number(price).toFixed(2)
  }
  var chargeStatus = function(status) {
    switch (status) {
      case 0:
        return '全部'
        break;
      case 1:
        return '成功'
        break;
      case 2:
        return '失败'
        break;
      case 3:
        return '受理中'
        break;
    }
  }
  module.exports = {
    toFixedFn:toFixedFn,
    chargeStatus:chargeStatus
  };
  </wxs>

<view class="order_con">
    <view class="item" wx:for="{{resultList}}" wx:key="index">
        <view class="item_money">
            <view class="item_left">金额</view>
            <view>¥{{m1.toFixedFn(item.orderPrice/100)}}元</view>
        </view>
    </view>
</view>

这样就可以按照所需要的显示啦。

ღ( ´・ᴗ・` )❤完。

发布了270 篇原创文章 · 获赞 50 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/Miss_liangrm/article/details/103278100
wxs