WeChat applet calls unsupported methods in wxml

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
  1. Create a filter.wxs
  2. Introduce filter.wxs on the applicable page
  3. 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() {}
})

Guess you like

Origin blog.csdn.net/qq_25992675/article/details/97788944