在 firebase 的游戏集合中的 likes 字段上有一个更改请求,其中 likes 是一个包含用户 ID 的数组
like() {
class DBwork {
constructor(FirebaseVariable) {
this.db = FirebaseVariable;
}
SetLike(game,user){
return new Promise(resolve => {
this.db.firestore().collection('games').doc(game).update({
"likes": firebase.firestore.FieldValue.arrayUnion(user)
})
});
}
}
var variable = new DBwork(firebase);
variable.SetLike(this.game, this.currentUserId).then(r =>{
console.log(r.data());
});
}
如果第一个参数是游戏 this.game 的实例,这是一个包含每个游戏信息的对象,则会发生错误:
Uncaught (in promise) FirebaseError: Function CollectionReference.doc() 要求其第一个参数为非空字符串类型,但它是:自定义 Object 对象
如果字符串 this.game.name 作为参数传递,则不会发生任何事情。
关于这张唱片是什么的一些想法:
return new Promise(resolve => {
此条目丢失
var result=""
resolve(result);
});
但我不知道该写什么以及如何写。
一个工作请求的示例,尽管在 firebase 中规则一直在变化,并且相关性取决于规则的版本。