微信小程序多列表渲染数据开关互不影响的实现
程序员文章站
2022-04-09 16:14:57
最近在学习小程序,正好发现一个问题,微信小程序多列表渲染数据开关怎么互不影响,记录一下,分享给大家
最近在学习小程序,正好发现一个问题,微信小程序多列表渲染数据开关怎么互不影响,记录一下,分享给大家
<!--pages/list/list.wxml--> <wxs src="../../utils/filter.wxs" module="filter" /> <view class="list"> <view wx:for="{{list}}" wx:key="{{index}}" class="ban" data-main='{{index}}'> <view class="time">{{filter.replacestar(index)}}</view> <view wx:for="{{item}}" wx:key="*this" class="cen ovf" data-id='{{item.id}}' data-index='{{index}}' > <navigator url="../details/details?id={{item.id}}" open-type="navigate" class="ovf item_1"> <view> <view class="name">{{item.ymname}}</view> <view class="msg">{{item.ymms}}</view> </view> </navigator> <view class="check ovf"> <view id="jl" bindtap='cancle' wx:if="{{item.seleced==1}}" data-fid='{{item.fid}}' data-id='{{item.id}}' data-index='{{index}}'>已记录</view> <picker mode="date" data-id='{{item.id}}' data-index='{{index}}' data-fid='{{item.fid}}' bindchange="binddatechange" bindcancel="bindcancel" class="item_2" name="picker" wx:if="{{item.seleced!=1}}"> <view id="jl" bindchange="checkboxchange" value='{{date}}'>记录</view> </picker> <view class="zi" wx:if="{{item.seleced==1}}">{{item.time}}</view> </view> </view> </view> </view> <view class="fix" bindtap='wait'> <text>查看待\n打疫苗</text> </view>
// pages/list/list.js const app = getapp() var time ='' page({ data: { id:0, list: [], date:'', tr:'', s:'' }, //事件处理函数 // bindcancel:function (e) { // var that = this // console.log(e.target.dataset.id) // that.setdata({ // tr: 1, // }) // }, binddatechange:function (e) { console.log('picker发送选择改变,携带值为', e.detail.value) time = e.detail.value var that = this var arr = that.data.list var index = e.target.dataset.index var index1 = e.target.dataset.fid arr[index1][index].seleced = 1 arr[index1][index].time = e.detail.value that.setdata({ id: e.target.dataset.id, date: time, list: arr }) }, cancle:function (e) { var that = this var arr = that.data.list var index = e.target.dataset.index var index1 = e.target.dataset.fid arr[index1][index].seleced = '' that.setdata({ id: e.target.dataset.id, list: arr }) }, wait:function () { wx.navigateto({ url: '../wait/wait' }) }, lis: function () { wx.navigateto({ url: '../archives/archives' }) }, onload: function () { var that = this wx.request({ url: 'https://m.renyiwenzhen.com/xcx_ajax.php?action=yimiaolist', //仅为示例,并非真实的接口地址 method: 'post', header: { 'content-type': 'application/json' // 默认值 }, success(res) { console.log(res.data) that.setdata({ list: res.data }) } }) } })
总结:
这里使用了双层循环,需要注意的是使用wx:key='*this'
循环本身
使用wx:if="{{item.seleced==1}}"
标记点击效果,给数据自定义属性
arr[index1][index].seleced = 1
到此这篇关于微信小程序多列表渲染数据开关互不影响的实现的文章就介绍到这了,更多相关小程序多列表渲染互不影响内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
上一篇: redis操作学习记录