[英]Save with firebase with a dynamic key name
I am trying to insert in my database the month chosen by the user. 我试图在数据库中插入用户选择的月份。
saveInBdd (){
this.errors = [];
const user = firebase.auth().currentUser;
user.updateProfile({
displayName: this.firstname,
}).then(()=>{
this.saveUserToUsersRef(user)
}, error => {
this.errors.push(error.message)
})
},
saveUserToUsersRef(user){
return this.usersRef.child(user.uid).update({
tab1: { this.months[0].selectedOption : "test"}
})
},
This code returns this error to me: 此代码将此错误返回给我:
The property name of a JSON object in the notation you're using needs to be a literal. 您正在使用的符号中的JSON对象的属性名称必须为文字。 To use a variable as the name of a property, use
[]
notation: 要将变量用作属性名称,请使用
[]
表示法:
saveUserToUsersRef(user){
var updates = {};
updates[this.months[0].selectedOption] = "test";
return this.usersRef.child(user.uid).update(updates))
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.