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

发布于 8 年前作者 ezeng2050 次浏览最后编辑 8 年前来自 ask

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

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

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

3 回复
mren
mren1 楼6 年前

<wxs module=“helper”>

    function includes(str, s){

        return str.indexOf(s)!=-1

}

</wxs>

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

naqiao
naqiao2 楼6 年前

wxs里面用indexOf啦

chenjing
chenjing3 楼6 年前

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