前言:在小程序的開發(fā)中,我們?cè)趘iew中便利data中數(shù)組或?qū)ο髸r(shí),很多情況下需要在js中動(dòng)態(tài)改變數(shù)組或者對(duì)象中某一香的屬性值。
創(chuàng)新互聯(lián)公司2013年成立,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目做網(wǎng)站、成都網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元市南做網(wǎng)站,已為上家服務(wù),為市南各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575
效果圖:
wxss如下:
.hd-cont { height: 126rpx; white-space: nowrap; padding-left: 20rpx; color: #fff; font-size: 28rpx; box-sizing: border-box; } .date-cont { width: 40rpx; margin-right: 70rpx; height: 100%; display: inline-block; padding-top: 10rpx; box-sizing: border-box; text-align: center; } .curl { width: 40rpx; height: 40rpx; border-radius: 50%; line-height: 40rpx; } .date-cont view:first-child { margin-bottom: 20rpx; } .focus { display: inline-block; width: 40rpx; height: 40rpx; font-family: Monaco;">#fff; color: #16cc80; border-radius: 50%; line-height: 40rpx; }
wxjs如下:
實(shí)現(xiàn)思路:點(diǎn)擊某一個(gè)日期時(shí),獲取當(dāng)前點(diǎn)擊的下表,點(diǎn)擊事件bindtap可以獲取到所點(diǎn)擊的元素的自定義屬性,也就是所點(diǎn)擊的元素的在data中數(shù)組的下標(biāo),點(diǎn)擊觸發(fā),清空所有對(duì)象中selected的值,然后將所點(diǎn)擊的下標(biāo)的selected值變?yōu)閒ocus就可實(shí)現(xiàn)點(diǎn)擊某一元素動(dòng)態(tài)改變數(shù)組中的某一屬性值。
Page({ data: { sDate: [ { "week": "日", "date": "01" ,"selected": "focus" }, { "week": "一", "date": "02", "selected": " " }, { "week": "二", "date": "03", "selected": " " }, { "week": "三", "date": "04", "selected": " " }, { "week": "四", "date": "05", "selected": " " }, { "week": "五", "date": "06", "selected": " " }, { "week": "六", "date": "07", "selected": " " }, { "week": "日", "date": "08", "selected": " " }, { "week": "一", "date": "09", "selected": " " }, { "week": "二", "date": "10", "selected": " " }, { "week": "三", "date": "11", "selected": " " }, { "week": "四", "date": "12", "selected": " " }, { "week": "五", "date": "13", "selected": " " }, { "week": "六", "date": "14", "selected": " " }, ] }, select: function (e) { var oIndex = e.currentTarget.dataset.index; var array = this.data.sDate; array.forEach( (item,index,arr) => { var sItem = "sDate["+ index + "].selected"; this.setData({ [sItem]: " " }) console.log([sItem]); if(index == oIndex) { var oSelected = "sDate[" + index + "].selected"http://這里需要將設(shè)置的屬性用字符串進(jìn)行拼接 this.setData({ [oSelected]: "focus" }) } }) }, })
總結(jié)
以上所述是小編給大家介紹的微信小程序開發(fā)之改變data中數(shù)組或?qū)ο蟮哪骋粚傩灾担M麑?duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
網(wǎng)頁標(biāo)題:微信小程序開發(fā)之改變data中數(shù)組或?qū)ο蟮哪骋粚傩灾?/a>
當(dāng)前網(wǎng)址:http://jinyejixie.com/article28/ijcejp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、品牌網(wǎng)站制作、外貿(mào)建站、網(wǎng)站收錄、網(wǎng)站設(shè)計(jì)、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)