小程序过滤器

1、创建 wxs 文件

// indexOf.wxs
function indexOf11(a, b) {
  if (a.indexOf(b) >= 0) {
    return true;
  } else {
    return false;
  }
}

module.exports = {
  indexOf11: indexOf11,
};

2、文件内使用

<!-- 文件内引入 并任意设置一个别名 此处使用str -->
<wxs src="../../utils/indexOf.wxs" module="str" />
<view
  wx:for="{{chatRecordList}}"
  wx:for-item="item"
  wx:for-index="index"
  wx:key="item"
  class="itemitemitem"
  id="{{item.idd}}"
>
  <view wx:if="{{myemchatId==item.to}}" class="left">
    <view>
      <image
        src="{{userInfo.userInfo.userIcon}}"
        style="width: 80rpx;height: 80rpx;border-radius: 50%;"
      ></image>
      <view class="text" wx:if="{{item.data}}">
        <view
          wx:if="{{item.data}}"
          wx:for="{{item.data}}"
          wx:for-item="item_"
          wx:key="item_"
          wx:for-index="index_"
          class="cccc"
        >
        <!-- 此处使用 判断item_内是否包含./faces/ee_ -->
          <text wx:if="{{str.indexOf11(item_,'./faces/ee_')?false:true}}"
            >{{item_}}</text
          >
          <image src="{{item_}}" wx:else class="emoemoemo"></image>
        </view>
      </view>
      <view class="imageEmchat" wx:if="{{item.url}}">
        <image src="{{item.url}}" style="width: 400rpx;height: 400rpx;"></image>
      </view>
    </view>
  </view>
  <view wx:else class="right">
    <view>
      <image
        src="{{myAvatar}}"
        style="width: 80rpx;height: 80rpx;border-radius: 50%;"
      ></image>
      <view class="text">{{item.msg||item.data}}</view>
    </view>
  </view>
</view>