wx: wx.showModal 回調函數中調用自定義方法


一、在回調函數中調用自定義方法:

回調函數中不能直接使用this,需要在外面定義 var that = this 然后 that.自定義的方法。如下:

  //刪除
  onDelete: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '確定要刪除?',
      success: function (res) {
        if (res.confirm) {
          that.onEdit(e);
        }
      }
    })
  },
  //編輯
  onEdit: function (e) {
    console.log('編輯');
  },

二、詳解彈框wx.showToast、wx.showModal、wx.showActionSheet,modal控件解釋及input輸入框值的獲取

(1)、wx.showToast

  wx.showToast({
    title: '失敗',//提示文字
    duration: 2000,//顯示時長
    mask: true,//是否顯示透明蒙層,防止觸摸穿透,默認:false  
    icon: 'success', //圖標,支持"success"、"loading"  
    success: function () { },//接口調用成功
    fail: function () { },  //接口調用失敗的回調函數  
    complete: function () { } //接口調用結束的回調函數  
  })

(2)、wx.showModal

  wx.showModal({
    title: '刪除圖片',
    content: '確定要刪除該圖片?',
    showCancel: true,//是否顯示取消按鈕
    cancelText: "",//默認是“取消”
    cancelColor: 'skyblue',//取消文字的顏色
    confirmText: "",//默認是“確定”
    confirmColor: 'skyblue',//確定文字的顏色
    success: function (res) {
      if (res.cancel) {
        //點擊取消,默認隱藏彈框
      } else {
        //點擊確定
        temp.splice(index, 1),
          that.setData({
            tempFilePaths: temp,
          })
      }
    },
    fail: function (res) { },//接口調用失敗的回調函數
    complete: function (res) { },//接口調用結束的回調函數(調用成功、失敗都會執行)
  })

(3)、wx.showActionSheet

  wx.showActionSheet({
    itemList: ['列1', '列2', '列3'],//顯示的列表項
    success: function (res) {//res.tapIndex點擊的列表項
      console.log("點擊了列表項:" + that[res.tapIndex])
    },
    fail: function (res) { },
    complete: function (res) { }
  })


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM