demo场景:
有两个数组,页面渲染一个数组1,数组2中有数组1随机下标的值,判断数组1是否包含数组2的值,如果包含了就改变当前下标的背景颜色。
index.wxml
<wxs module="m1">
function fn(arr, arg) {
var result = {
indexOf: false,
toString: ''
}
result.indexOf = arr.indexOf(arg) > -1;
result.toString = arr.join(",");
return result;
}
module.exports.fn = fn;
</wxs>
<block wx:for='{{arr}}' wx:key=''>
<view class="item " catchtap="click_yuan" data-item="{{item.i}}" style="background: {{m1.fn(seccArr, item.i).indexOf ? 'red':''}};">
{{item.i}}
</view>
</block>
index.js
Page({
data: {
arr:[{"www":16,"hhh":72,"i":1},{"www":157,"hhh":139,"i":2},{"www":206,"hhh":268,"i":3},{"www":208,"hhh":111,"i":4},{"www":205,"hhh":53,"i":5},{"www":60,"hhh":17,"i":6},{"www":151,"hhh":192,"i":7},{"www":70,"hhh":115,"i":8},{"www":101,"hhh":246,"i":9},{"www":253,"hhh":75,"i":10},{"www":280,"hhh":182,"i":11},{"www":75,"hhh":203,"i":12},{"www":306,"hhh":20,"i":13},{"www":287,"hhh":120,"i":"一"},{"www":203,"hhh":193,"i":"二"},{"www":11,"hhh":132,"i":"三"},{"www":141,"hhh":70,"i":"四"},{"www":226,"hhh":7,"i":"五"},{"www":91,"hhh":158,"i":"六"},{"www":303,"hhh":273,"i":"七"},{"www":1,"hhh":29,"i":"八"},{"www":137,"hhh":300,"i":"九"},{"www":4,"hhh":210,"i":"十"},{"www":112,"hhh":24,"i":"十一"},{"www":33,"hhh":287,"i":"十二"}],
seccArr:[1,"一",2,"二",3,"三"]
}
})