這篇文章主要為大家展示了“微信小程序中實(shí)現(xiàn)動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理的示例分析”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“微信小程序中實(shí)現(xiàn)動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理的示例分析”這篇文章吧。
成都創(chuàng)新互聯(lián)-云計(jì)算及IDC服務(wù)提供商,涵蓋公有云、IDC機(jī)房租用、四川雅安服務(wù)器托管、等保安全、私有云建設(shè)等企業(yè)級(jí)互聯(lián)網(wǎng)基礎(chǔ)服務(wù),來(lái)電聯(lián)系:18982081108微信小程序 動(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ǎng)按,則不再執(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)網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站muchs.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站欄目:微信小程序中實(shí)現(xiàn)動(dòng)態(tài)綁定數(shù)據(jù)及動(dòng)態(tài)事件處理的示例分析-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://muchs.cn/article38/dpijpp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、網(wǎng)站導(dǎo)航、面包屑導(dǎo)航、網(wǎng)站設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站排名
聲明:本網(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í)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容