条件渲染内如何检测字符串是否包含某个字符
发布于 6 年前 作者 ezeng 1867 次浏览 来自 问答

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

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

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

3 回复

<wxs module=“helper”>

    function includes(str, s){

        return str.indexOf(s)!=-1

}

</wxs>

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

wxs里面用indexOf啦

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

回到顶部