How to replace indexof (recommended)

Time:2020-6-22

Method: define indexof method through WXS, reference and use in page

Chestnut:

WXS: named str.wxs , the defineindexof method of the export definition, named indexof


function defineIndexOf(str, val) {
 return str.indexOf(val);
}
module.exports = {
 indexOf: defineIndexOf
}

wxml:

quote str.wxs , and name the module toolstr. In the following loop, you need to use the indexof method exported from toolstr


<wxs src="../../../../utils/str.wxs" module="toolStr" />
<view wx:for="{{list}}" wx:key="index"

 bindtap="clickf" data-id="{{item.id}}">{{item.name}}</view>

PS: look at the alternative method that wechat applet does not support indexof

Use lastIndexOf, but the order is the opposite of indexof

summary

The above is the replacement method of indexof, a wechat applet introduced by Xiaobian to you. I hope it can help you. If you have any questions, please leave a message to me, and Xiaobian will reply to you in time. Thank you very much for your support of the developepaer website!
If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!