微信小程序前端調用後臺方法並獲取返回值

wxml代碼

<wxs src="../../wxs/string.wxs" module="tools" />

<!-- 調用tools.img(item.content)返回bool,也能夠返回其餘值 -->
<view class='clearfix' wx:if="{{tools.img(item.content)}}">
    <view class='content-view'>
        <image src='{{item.content}}' mode='widthFix'></image>
    </view>
</view>

js代碼

var img = function (val) {
  if (val.length == 0 || val == undefined) {
    return;
  }
  if (val.indexOf("png") > -1 || val.indexOf("gif") > -1){
    return true;
  }else{
    return false;
  }
}
相關文章
相關標籤/搜索