使用wxs
在pages同一级别目录下创建utils文件夹,在utils文件夹下创建utils.wxs
utils.wxs
function includes(array, value) {
if (!array || !array.length) return false;
return array.indexOf(value) !== -1;
}
module.exports = {
includes: includes
};
需要使用includes的wxml文件
<wxs src="../../utils/utils.wxs" module="array" />
<view wx:for="{{msg}}" wx:key="id"
class="{{array.includes(需要判断的数组, item.id) ? 'select' : ''}}"> AA </view>