Page({
data: {
id: ,//修改用来保存_id
iSshow: true,
inpVal: ,
inp2Val: ,
inp3Val: ,
list: []
},
onLoad: function () {
var that = this
that.getUserMsg()//读取信息
},
//获取文本框内容
getName(e) {
this.setData({
inpVal: e.detail.value
})
},
getAge(e) {
this.setData({
inp2Val: e.detail.value
})
},
getCreated(e) {
this.setData({
inp3Val: e.detail.value
})
},
//获取信息
getUserMsg() {
var that = this
const db = wx.cloud.database()
db.collection(datalist).get({
success: function (res) {
console.log(res)
that.setData({
list: res.data
})
}
})
},
//添加信息
setUserMsg() {
var that = this
const db = wx.cloud.database()
db.collection(datalist).add({
data: {
name: that.data.inpVal,
age: that.data.inp2Val,
created: that.data.inp3Val
},
success: function (res) {
console.log(res)
that.setData({
inpVal: "",
inp2Val: "",
inp3Val:""
})
console.log(that.data.inpVal + -- + that.data.inp2Val + -- + that.data.inp2Val)
that.getUserMsg()
}
})
},
//删除信息
delUserMsg(e) {
var that = this
const db = wx.cloud.database()
var id = e.currentTarget.dataset.id
db.collection(datalist).doc(id).remove({
success: function (res) {
console.log(res)
that.getUserMsg()
}
})
},
//修改回显
changeMsg(e) {
var that = this
var id = e.currentTarget.dataset.id
const db = wx.cloud.database()
db.collection(datalist).doc(id).get({
success: function (res) {
that.setData({
inpVal: res.data.name,
inp2Val: res.data.age,
inp3Val:res.data.created,
show: false,
id: res.data._id
})
}
})
},
//更新提交
updetMsg(e) {
var that = this
var id = e.currentTarget.dataset.id
const db = wx.cloud.database()
db.collection(datalist).doc(id).update({
data: {
name: that.data.inpVal,
age: that.data.inp2Val,
created:that.data.inp3Val
},
success: function (res) {
that.getUserMsg()
that.setData({
inpVal: ,
inp2Val: ,
inp3Val:,
show: true
})
}
})
},
})
暂时没有评论,来抢沙发吧~