WeChat applet calls unsupported methods in wxml
Demo site : https://download.csdn.net/download/qq_25992675/11453516
Example: Use indexOf in wxml
Steps for usage
- Create a filter.wxs
- Introduce filter.wxs on the applicable page
- Instructions
1. Create a filter.wxs
/*
* 需要使用的方法
*/
var indexOf = function (array,index) {
return array.indexOf(index)
}
/*
* 导出方法:左边的filter.wxs中的方法名,右边是页面引入的方法名
*/
module.exports = {
indexOf: indexOf
}
2. Introduce filter.wxs on the applicable page
<wxs module="filters" src="../../utils/filter.wxs"></wxs>
3. Use the method on the applicable page (the part in bold is the calling method)
<view class="container">
<view wx:for="{
{list}}" wx:key="{
{index}}">
<text class="{
{(filter.indexOf(otherList,item))>-1?'changColor':''}}">{
{item}}</text>
</view>
</view>
js part of the code
//获取应用实例
const app = getApp()
Page({
data: {
list: [1, 2, 3, 4, 5],
otherList: [1, 3, 5]
},
onLoad: function() {}
})