微信小程序云开发多个字段怎么传入两张表里面
发布于 5 年前 作者 schang 9683 次浏览 来自 问答

微信小程序云开发多个字段怎么传入两张表里面,这样写哪里错了

// pages/companyInfo/companyInfo.js

const db = wx.cloud.database({

env: ‘znyz-30f4bf’

})

Page({

/*页面的初始数据*/

data: {

company:"",

phoneNumber:"",

password:""

},

onChange0: function (event) {

this.setData({

company: event.detail

})

},

onChange1: function (event) {

this.setData({

phoneNumber: event.detail

})

},

onChange2: function (event) {

this.setData({

password: event.detail

})

},

addUser: function () {

if (this.data.company != “” && this.data.phoneNumber != “” && this.data.password != “”) {

this.addCompany();

}

},

//添加一个公司

//往companyinfo传公司名称跟id

addCompany: function () {

var that = this;

db.collection(‘companyinfo’).add({

data: {

company: that.data.company,

},

success(res) {

console.log(res)

wx.navigateBack({

delta: 1

})

},

fail: console.error

})

},

//往userinfo传联系方式跟密码

addCompany: function () {

var that = this;

db.collection(‘userinfo’).add({

data: {

phoneNumber: that.data.phoneNumber,

password: that.data.password,

},

success(res) {

console.log(res)

wx.navigateBack({

delta: 1

})

},

fail: console.error

})

},

})

1 回复

addCompany函数写了两次,这种情况应该只会执行最后一个

回到顶部