chen214123158
chen214123158
  • 发布:2020-07-07 12:02
  • 更新:2020-07-07 13:47
  • 阅读:1074

uniCloud 云函数修改数据失败(修复方法语法问题)?

分类:uniCloud
   // 业务方法  
   editFunc() {  
				uni.showLoading({  
					title: '处理中...'  
				})  
				uniCloud.callFunction({  
					name: 'dna_update',  
					data: {  
							_id:this.dataForm.id,  
							name:this.dataForm.name,  
							color:this.dataForm.color,  
							val:this.dataForm.val  
						}  
				}).then((res) => {  
					uni.hideLoading()  
					uni.showModal({  
						content: `成功`,  
						showCancel: false  
					})  
				}).catch((err) => {  
					uni.hideLoading()  
					uni.showModal({  
						content: `修复数据失败,错误信息为:${err.message}`,  
						showCancel: false  
					})  
					console.error(err)  
				})  
			}  
  
// 云函数  
'use strict';  
const db = uniCloud.database()  
exports.main = async (event, context) => {  
	const collection = db.collection('HVB-DNA')  
	collection.doc('_id').update({  
		data:{  
			name:	event.data.name,  
			color:	event.data.color,  
			val:	event.data.val  
		}  
	}).then(res=>{  
		if (res.updated === 1) {  
			let result = Object.assign({}, {  
				_id: event.data.id  
			}, event)  
			return {  
				status: 0,  
				msg: `集合数据由${JSON.stringify(docList.data[0])}修改为${JSON.stringify(result)}`  
			}  
		} else {  
			return {  
				status: -1,  
				msg:'集合'+table+'内没有数据'  
			}  
		}  
	}).catch(e=>{console.log(msg)});;  
};

异常问题:
12:02:03.326 [云函数:dna_update] 运行日志:
12:02:03.326 Cannot read property 'name' of undefined
12:02:03.326 TypeError: Cannot read property 'name' of undefined
12:02:03.327 at exports.main (/tmp/function/__index.js:7:21)
12:02:03.327 at module.exports (/tmp/function/index.js:94:26)
12:02:03.327 at runUserFunction (/code/index.js:114:181586)
12:02:03.327 at (<anonymous>)
12:02:03.328 at _tickCallback (internal/process/next_tick.js:188:7)

2020-07-07 12:02 负责人:无 分享
已邀请:
chen214123158

chen214123158 (作者)

已解决

该问题目前已经被锁定, 无法添加新回复