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


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;
  }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM