最新国产好看的视频,伊人天堂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后臺中知道是點(diǎn)擊了哪個image,上傳圖片后再循環(huán)得出相等data-type的數(shù)據(jù)項(xiàng)進(jìn)行賦值,這樣就能動態(tài)給相應(yīng)的標(biāo)簽賦值

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, //默認(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返回的是一個字符串,需進(jìn)行轉(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)文章

最新評論

洮南市| 昌平区| 静海县| 城步| 英吉沙县| 余姚市| 阳朔县| 凤阳县| 石屏县| 仁怀市| 获嘉县| 岳普湖县| 武山县| 甘洛县| 大渡口区| 田东县| 黄龙县| 绥芬河市| 丹棱县| 曲阳县| 从江县| 巴林右旗| 威远县| 永川市| 揭西县| 华亭县| 纳雍县| 开化县| 渭源县| 沾益县| 清水县| 灌云县| 红原县| 桐庐县| 旬阳县| 滦平县| 惠东县| 和硕县| 任丘市| 天津市| 综艺|