Posted in Javascript onJune 05, 2020
最近在学习小程序,正好发现一个问题,微信小程序多列表渲染数据开关怎么互不影响,记录一下,分享给大家
<!--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
到此这篇关于微信小程序多列表渲染数据开关互不影响的实现的文章就介绍到这了,更多相关小程序多列表渲染互不影响内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!
微信小程序多列表渲染数据开关互不影响的实现
- Author -
Vam的金豆之路声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@