js文件部分代码
changebackground:function(e){
var that = this;
var index = e.currentTarget.dataset.idx;//获取点击的索引
var arr = that.data.deviceList; //获取数组
arr[index].ups = 1;
that.setData({ //更新数据
deviceList: arr
})
},
wxml文件 部分 代码
<view class="container" style="height:{{height}}rpx;" scroll-y="true" scroll-with-animation="true" bindscrolltolower="getRGshow">
<scroll-view scroll-y="true" style="width:100%;min-height:100%;">
<view class="goods-box" wx:for="{{deviceList}}" wx:key="id" wx:for-index="idx" wx:for-item="item" data-id="{{item.id}}"bindtap="toDetailsTap">
<template is="device-list" data="{{item:item,idx:idx,items:items}}"> </template>
</view>
<view class='adddevice' bindtap="click">
<image class="addpic" src="/images/add.png" mode="aspectFill"></image>
</view>
</scroll-view>
</view>
template 文件
部分
代码
<template name="device-list">
<view class='adddevice' data-text="{{item.deviceId}}" data-idx="{{idx}}" style="background:{{item.ups==1?'#AAAAAA':'#FFFFFF'}};" bindtouchstart="changebackground" bindtouchend='controlurl'>
<view class="{{colors}}">微蒸烤一体机</view>
<image class="deviceimages" src="../../images/kaoxiangon.png" mode="aspectFit"></image>
<image class="connectimages" src="../../images/connecton.png" mode="aspectFit"></image>
</view>
</template>