最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序 動態(tài)綁定數(shù)據(jù)及動態(tài)事件處理

 更新時間:2017年03月14日 11:21:20   投稿:lqh  
這篇文章主要介紹了微信小程序 動態(tài)綁定數(shù)據(jù)及動態(tài)事件處理的相關(guān)資料,需要的朋友可以參考下

微信小程序 動態(tài)綁定數(shù)據(jù)及動態(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后臺中知道是點擊了哪個image,上傳圖片后再循環(huán)得出相等data-type的數(shù)據(jù)項進行賦值,這樣就能動態(tài)給相應(yīng)的標簽賦值

addtaskimg 為統(tǒ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, //默認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返回的是一個字符串,需進行轉(zhuǎn)換成objcet,wx不識別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  
        })        
       }
      })
    }
   })
 }

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

相關(guān)文章

最新評論

甘肃省| 巴彦县| 同江市| 昭苏县| 思南县| 镇远县| 革吉县| 钟祥市| 肥城市| 渝中区| 榆中县| 宣恩县| 淳安县| 涿州市| 九台市| 富平县| 微山县| 石嘴山市| 新巴尔虎右旗| 江山市| 平遥县| 武穴市| 扎鲁特旗| 西宁市| 西贡区| 盐池县| 梁山县| 宝鸡市| 孝义市| 武穴市| 贵阳市| 黑河市| 进贤县| 封开县| 龙里县| 临洮县| 论坛| 都匀市| 霍城县| 屯门区| 伊通|