国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

微信小程序 動態綁定數據及動態事件處理

2024-05-06 16:35:51
字體:
來源:轉載
供稿:網友

微信小程序 動態綁定數據及動態事件處理

關鍵核心代碼

<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);        //重置圖片參數        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后臺中知道是點擊了哪個image,上傳圖片后再循環得出相等data-type的數據項進行賦值,這樣就能動態給相應的標簽賦值

addtaskimg 為統一的動態事件

主要代碼如下

.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)  {   //處理如果是長按,則不再執行下面的   this.setData({    blongtap:false   });   return;  }  var that = this;   wx.chooseImage({    count:1, //默認1張    success:function(res){      //先上傳至服務器,再返回路徑供保存      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返回的是一個字符串,需進行轉換成objcet,wx不識別eval函數        console.log(res.Data);        var objurl= JSON.parse(res.data);        //重置圖片參數        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          })               }      })    }   }) }

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 晴隆县| 武冈市| 汕头市| 南川市| 绥宁县| 福贡县| 临高县| 台南县| 谷城县| 彭水| 伊春市| 包头市| 屏东市| 江北区| 上杭县| 乌什县| 中山市| 潼南县| 南和县| 嘉鱼县| 阿拉善左旗| 溆浦县| 定远县| 岳池县| 利津县| 兰考县| 临沧市| 香港| 石河子市| 池州市| 武隆县| 银川市| 武宣县| 息烽县| 德保县| 甘孜| 福海县| 米泉市| 建始县| 吴忠市| 宾阳县|