收藏
回答

条件渲染内如何检测字符串是否包含某个字符

框架类型 问题类型 终端类型 微信版本 基础库版本
小程序 需求 客户端 7.0 2.4.2

条件渲染内如何检测字符串是否包含某个字符?


比如wx:if="{{str.indexOf('a') != -1}}"


如果不可以有办法实现吗?


回答关注问题邀请回答
收藏

4 个回答

  • 杨泉
    杨泉
    2019-01-17

    <wxs module="helper">

        function includes(str, s){

            return str.indexOf(s)!=-1

    }

    </wxs>


    <view wx:if="{{helper.includes(str, 'a')}}" />

    2019-01-17
    有用 3
    回复 1
    • undefined
      undefined
      2019-05-26

      <wxs module="helper">

      function includes(str, s){

      return 1

      return str.indexOf(s)!=-1

      }

      module.exports.includes = includes;

      </wxs>


      2019-05-26
      回复
  • 禾店短剧系统
    禾店短剧系统
    2021-06-18

    可以用正则表达式:

    public class RegexTest {

    public static void main(String args[]) {


    Pattern pattern = Pattern.compile("oWor");

    Matcher matcher = pattern.matcher("HelloWorld");

    if(matcher.find()) {

    System.out.println("Bingo!");

    }else{

    System.out.println("No substring here!");

    }


    }

    }

    2021-06-18
    有用 1
    回复
  • 卢霄霄
    卢霄霄
    2019-01-17

    wxs里面用indexOf啦

    2019-01-17
    有用 1
    回复
  •  向阳
     向阳
    2019-01-17

    在js里写一个方法应该可以调用

    2019-01-17
    有用
    回复
登录 后发表内容