我需要将一个对象推送到节点追随者中,但我没有找到方法。
我试试这个:
this.af.database.list(`profile/${user}/followers/`).push({[from]: true});
我需要下一个输出
有什么想法吗?
最佳答案
使用push()
将使用自动生成的随机唯一ID将新节点推送到列表中。如果您需要设置特定值,则需要使用 set()
来代替:
this.af.database.object(`profile/${user}/followers/${from}`).set(true);
在此示例中,我使用 object()
而不是 list()
直接创建对要创建的列表中的值的引用,其中 ${from}
与 的值相同[来自]
在您的代码中。
或者,您可以使用 update()
方法:
this.af.database.object(`profile/${user}/followers`).update({[from]: true});
关于Firebase 推送项目自定义键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47003289/