亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這些代碼怎樣復用?

這些代碼怎樣復用?

qq_殺意隆_0 2017-10-11 14:55:06
這是微信小程序的代碼1.if(!this.data.serveItem){ ?????????????? ????????????????????that.setData({? ????????????????????????loadingHide:false ????????????????????}) ?????????????????????//請求服務項目列表資源 ????????????????????wx.request({ ????????????????????????url:'https://bird.ioliu.cn/v1?url=http://aasss1.oschina.io/122/4.json', ????????????????????????success(res){ ????????????????????????????that.setData({ ?????????????????????????????????serveItem:res.data, ?????????????????????????????????tireServices:?res.data.tireServices, ?????????????????????????????????maintainServices:?res.data.maintainServices, ?????????????????????????????????installServices:?res.data.installServices, ????????????????????????????}) ????????????????????????????getElementHeight('#item-wrap1',that) ????????????????????????} ????????????????????}) ????????????????}2.if(!this.data.rates){ ????????????????????that.setData({ ????????????????????????loadingHide:false ????????????????????}) ????????????????????//?請求評價列表資源 ????????????????????wx.request({ ????????????????????????url:'https://bird.ioliu.cn/v1?url=http://aasss1.oschina.io/122/2.json', ????????????????????????success(res){ ????????????????????????????that.setData({ ????????????????????????????????rates:res.data.rates ????????????????????????????}) ????????????????????????????getElementHeight('#item-wrap2',that) ????????????????????????} ????????????????????}) ????????????????}3.if(!this.data.recommendList){ ????????????????????that.setData({ ????????????????????????loadingHide:false ????????????????????}) ????????????????????//?請求推薦列表資源 ????????????????????wx.request({ ????????????????????????url:'https://bird.ioliu.cn/v1?url=http://aasss1.oschina.io/122/recommendList.json', ????????????????????????success(res){ ????????????????????????????that.setData({ ????????????????????????????????recommendList:res.data.recommendList ????????????????????????????}) ????????????????????????????getElementHeight('#item-wrap3',that) ????????????????????????} ????????????????????}) ????????????????}上面3段代碼重復性高,于是我寫了個函數:function?requestResouce(that,oldObj,newObj,url,id){ ????if(!oldObj){ ????????that.setData({ ????????????loadingHide:false ????????}) ????????wx.request({ ????????????url:url, ????????????success(res){ ????????????????that.setData(newObj) ????????????????getElementHeight(id,that) ????????????} ????????}) ????} }結果代入參數后提示res is not defined。到底要怎樣寫才不會出錯?
查看完整描述

1 回答

?
Gotta

TA貢獻53條經驗 獲得超16個贊

控制臺你看你第幾行報錯了。似乎不是你寫的函數報錯,估計方法調來調去,傳參哪里傳錯了。

查看完整回答
反對 回復 2017-10-11
  • qq_殺意隆_0
    qq_殺意隆_0
    提示res is not defined
  • Gotta
    Gotta
    是啊 提示有一大坨。應該有告訴你是哪個方法報錯吧? 比如這樣 abc is not defined;at pages/index/index page test function ReferenceError: abc is not defined 看那個at
  • 1 回答
  • 0 關注
  • 1048 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號