gpt4 book ai didi

javascript - 使用 post 方法到 firebase 数据库的无效或意外 token

转载 作者:行者123 更新时间:2023-11-30 09:26:23 25 4
gpt4 key购买 nike

我正在尝试将静态数组插入到我的 firebase 数据库中。这就是我当前的数据库的样子。 enter image description here

我想创造的是这样的东西。 enter image description here

router.post('/:uuid', function (req, res) {
var ref = database.ref('watchers/' + req.params.uuid);
var body = _.pick(_.assign(addwatcher, req.body), _.keys(addwatcher));

body['createdAt'] = moment().format('YYYY-MM-DD HH:mm:ss');

body['totalRating'] = {1star:0,2star:0,3star:0,4star:0,5star:0,total:0};

ref.set(body);

res.send('Sucessfully authenticated!');

});

我正在使用这个脚本来保存我的 auth id 而不是 pushId,但是当我尝试创建数组时出现问题,它会在我的控制台上发送错误..

body['totalRating'] = {1star:0,2star:0,3star:0,4star:0,5star:0,total:0};
^
SyntaxError: Invalid or unexpected token

我只是想知道如何在 .post 方法上插入数组数据。

最佳答案

在 javascript 中命名变量时不能使用数字作为第一个字符。在您的开发人员控制台中尝试它,您会得到这个。

enter image description here

更新

如果你真的想实现,你可以这样做 {'1star': 0}。只需将 var 名称括在单引号(或双引号)之间即可。

enter image description here

关于javascript - 使用 post 方法到 firebase 数据库的无效或意外 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48922854/

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