這篇文章主要為大家展示了“微信小程序中實(shí)現(xiàn)動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理的示例分析”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“微信小程序中實(shí)現(xiàn)動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理的示例分析”這篇文章吧。
10余年的鄄城網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整鄄城建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)公司從事“鄄城網(wǎng)站設(shè)計(jì)”,“鄄城網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
微信小程序 動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理
關(guān)鍵核心代碼
<image class="midimage" data-Type="{{item.Type}}" data-BillCode="{{item.BillCode}}" data-src="{{item.imgurl}}" src="{{item.imgurl}}" mode="scaleToFill" bindtap="addtaskimg" bindlongtap="imglongtap" ></image>
var objurl= JSON.parse(res.data); //重置圖片參數(shù) var temppostionlist=that.data.postionlist; for (var i=0;i<temppostionlist.length;i++) { if (temppostionlist[i]["Type"]==e.currentTarget.dataset.type){ temppostionlist[i]["imgurl"]=temppaths; temppostionlist[i]["serverimgurl"]=objurl.Body.Data; break; } } that.setData( { postionlist:temppostionlist })
利用image的data-Type,可以在js后臺(tái)中知道是點(diǎn)擊了哪個(gè)image,上傳圖片后再循環(huán)得出相等data-type的數(shù)據(jù)項(xiàng)進(jìn)行賦值,這樣就能動(dòng)態(tài)給相應(yīng)的標(biāo)簽賦值
addtaskimg 為統(tǒng)一的動(dòng)態(tài)事件
主要代碼如下
.wxml
<scroll-view class="center" scroll-y="true"> <view class="midcenter" wx:for="{{postionlist}}"> <view class="mid_top" > <image class="smallimage" src="../images/my/XXH/line_title.png" mode="aspectFit" ></image> <text>{{item.KeyValue}}</text> </view> <view class="mid_center"> <text>{{item.Remark}}</text> </view> <view class="mid_bottom"> <image class="midimage" data-Type="{{item.Type}}" data-BillCode="{{item.BillCode}}" data-src="{{item.imgurl}}" src="{{item.imgurl}}" mode="scaleToFill" bindtap="addtaskimg" bindlongtap="imglongtap" ></image> </view> </view> </scroll-view>
.js
addtaskimg:function(e){ //添加選擇圖片 if (this.data.blongtap) { //處理如果是長按,則不再執(zhí)行下面的 this.setData({ blongtap:false }); return; } var that = this; wx.chooseImage({ count:1, //默認(rèn)1張 success:function(res){ //先上傳至服務(wù)器,再返回路徑供保存 var temppaths=res.tempFilePaths[0];//+".jpg"; wx.uploadFile({ url:app.globalData.ghost+"YWTask/PutUploadFile?BillCode="+that.data.detail.BillCode+"&ID="+that.data.id, filePath:temppaths, name:'image', formData:{}, success:function(res){ //res.data返回的是一個(gè)字符串,需進(jìn)行轉(zhuǎn)換成objcet,wx不識(shí)別eval函數(shù) console.log(res.Data); var objurl= JSON.parse(res.data); //重置圖片參數(shù) var temppostionlist=that.data.postionlist; for (var i=0;i<temppostionlist.length;i++) { if (temppostionlist[i]["Type"]==e.currentTarget.dataset.type){ temppostionlist[i]["imgurl"]=temppaths; temppostionlist[i]["serverimgurl"]=objurl.Body.Data; break; } } that.setData( { postionlist:temppostionlist }) } }) } }) }
以上是“微信小程序中實(shí)現(xiàn)動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站標(biāo)題:微信小程序中實(shí)現(xiàn)動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理的示例分析
分享鏈接:http://www.sd-ha.com/article33/iidpss.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、營銷型網(wǎng)站建設(shè)、App開發(fā)、移動(dòng)網(wǎng)站建設(shè)、用戶體驗(yàn)、Google
聲明:本網(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)