效果圖如下:
核心代碼如下:
delType:function(e){ var typeId = e.currentTarget.dataset['id']; console.log("delete:"+typeId) wx.showModal({ title: '提示', content: '確認要刪除該支出類型?', success: function (res) { if (res.confirm) { console.log('用戶點擊確定') wx.request({ url: getApp().globalData.urlPath + "spendingType/delete", method: "POST", data: { typeId: typeId }, header: { "Content-Type": "application/x-www-form-urlencoded" }, success: function (res) { console.log(res.data.code); if (res.statusCode == 200) { //訪問正常 if (res.data.code == "000000") { wx.showToast({ title: "刪除成功,返回支出類型列表", icon: 'success', duration: 3000, success: function () { wx.navigateTo({ url: '../type/type' }) } }) } } else { wx.showLoading({ title: '系統異常', fail }) setTimeout(function () { wx.hideLoading() }, 2000) } } }) } else if (res.cancel) { console.log('用戶點擊取消') } } }) }
wxml代碼如下:
<text bindtap='delType' data-id="{{item.typeId}}">刪除</text>
data-id相當於綁定對應的值,比方說你是根據id來刪除對應的數據。
bindtap,即綁定事件。