做小程序的时候,想在wxmll中直接使用substring截取想要的串,譬如以下这样写(发现行不通)
<view class="picker">
{{list[index].bankcard.substring(14,18)}}
</view>
后来找到解决方法如下:
1.创建js函数,然后在wxml去调用
界面效果:
<wxs src="../../wxs/sub.wxs" module="tools" />
<view class='extract'>
<view class='card'>
<text>到账银行卡</text>
<picker bindchange="bindPickerChange" value="{{index}}" range="{{list}}" mode="selector" range-key="{{'bankname'}}">
<view class="picker">
{{list[index].bankname}} ({{tools.sub(list[index].bankcard)}})
</view>
</picker>
</view>
<view class='money'>
<text>提现金额</text>
<view>
<text>¥</text>
<input type='digit' bindinput='money'></input>
</view>
</view>
<view class='tip'>
<text>当前零钱可提余额{{tqAmount}}元,</text>
<text>全部提现</text>
</view>
<button bindtap='extract' class='button' wx:if="{{showbtn}}">提现</button>
<button bindtap='extract' wx:else>提现</button>
</view>
var sub = function (val) {
if (val.length == 0 || val == undefined || "") {
return;
}
if (val.length > 0) {
return val.substring(val.length - 4, val.length) ;
} else {
return val;
}
}
module.exports.sub = sub;