微信小程序多列表渲染數(shù)據(jù)開關(guān)互不影響的實(shí)現(xiàn)
最近在學(xué)習(xí)小程序,正好發(fā)現(xiàn)一個(gè)問題,微信小程序多列表渲染數(shù)據(jù)開關(guān)怎么互不影響,記錄一下,分享給大家

<!--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:''
},
//事件處理函數(shù)
// bindcancel:function (e) {
// var that = this
// console.log(e.target.dataset.id)
// that.setData({
// tr: 1,
// })
// },
bindDateChange:function (e) {
console.log('picker發(fā)送選擇改變,攜帶值為', 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', //僅為示例,并非真實(shí)的接口地址
method: 'post',
header: {
'content-type': 'application/json' // 默認(rèn)值
},
success(res) {
console.log(res.data)
that.setData({
list: res.data
})
}
})
}
})
總結(jié):
這里使用了雙層循環(huán),需要注意的是使用wx:key='*this'循環(huán)本身
使用wx:if="{{item.seleced==1}}"標(biāo)記點(diǎn)擊效果,給數(shù)據(jù)自定義屬性
arr[index1][index].seleced = 1
到此這篇關(guān)于微信小程序多列表渲染數(shù)據(jù)開關(guān)互不影響的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)小程序多列表渲染互不影響內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
js獲取input長(zhǎng)度并根據(jù)頁(yè)面寬度設(shè)置其大小及居中對(duì)齊
這篇文章主要介紹了js獲取input長(zhǎng)度并根據(jù)頁(yè)面寬度設(shè)置其大小及居中對(duì)齊的方法,需要的朋友可以參考下2014-08-08
js中編碼函數(shù):escape,encodeURI與encodeURIComponent詳解
escape(), encodeURI()和encodeURIComponent()是在Javascript中用于編碼字符串的三個(gè)常用的方法,而他們之間的異同卻困擾了很多的Javascript初學(xué)者,這篇文章詳細(xì)的給大家介紹了js中編碼函數(shù):escape,encodeURI與encodeURIComponent的相關(guān)資料,需要的朋友可以參考下。2017-03-03
JS實(shí)現(xiàn)在頁(yè)面隨時(shí)自定義背景顏色的方法
這篇文章主要介紹了JS實(shí)現(xiàn)在頁(yè)面隨時(shí)自定義背景顏色的方法,實(shí)例分析了javascript操作css樣式的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02
javascript 獲取所有id中包含某關(guān)鍵字的控件的實(shí)現(xiàn)代碼
獲取某容器控件中id包含某字符串的控件id列表2010-11-11
JS獲取鼠標(biāo)坐標(biāo)并且根據(jù)鼠標(biāo)位置不同彈出不同內(nèi)容
這篇文章主要介紹了js獲取鼠標(biāo)坐標(biāo)并且根據(jù)鼠標(biāo)位置不同彈出不同內(nèi)容的實(shí)例代碼,需要的朋友可以參考下2017-06-06
js實(shí)現(xiàn)人才網(wǎng)站職位選擇功能的方法
這篇文章主要介紹了js實(shí)現(xiàn)人才網(wǎng)站職位選擇功能的方法,涉及javascript動(dòng)態(tài)操作頁(yè)面元素結(jié)點(diǎn)的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-08-08

