gpt4 book ai didi

javascript - 使用 Firebase 存储数组

转载 作者:行者123 更新时间:2023-11-28 18:22:04 26 4
gpt4 key购买 nike

在 Firebase 中,我有函数 addSubmit,该函数用于将数据 Do the trees 提交到名为 addnote 的数组。但是,我不知道如何让 push 方法发送到数组。我的代码如下。

addSubmit(){
var self = this;
var user = firebase.auth().currentUser;
var getUserInfo = firebase.database().ref('users/' + user.uid);

if (user){
getUserInfo.push({
addnote: ["Do the dishes"]
});
}
}

我的推送方法最终给了我几个 addnote 数组,而不是将所有 Do the trees 字符串放在同一个数组中。所以它看起来像:

addnote - 'Do the dishes'
addnote - 'Do the dishes'

相对于:

addnote - 'Do the dishes', 'Do the dishes'

我将如何重新组织我的代码以使其工作?

最佳答案

我认为您正在寻找:

getUserInfo.child("addnote").push("Do the dishes");

关于javascript - 使用 Firebase 存储数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39736527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com