在firebase对象中创建嵌套数组 [英] Creating nested array in firebase Object

查看:64
本文介绍了在firebase对象中创建嵌套数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将值推送到存储在我的Firebase数据库中的嵌套数组中.目标看起来像这样:

I want to push a value to a nested array which is stored in my firebase database. The target looks like this:

我正在查询Firebase数据库并接收快照.有了这个快照,我想存储我的更改.如果我推送新值,它将在firebase中创建我:

I'm query the firebase database and receive snapshot. With this snapshot I want to store my changes. If i push the new value it creates me in firebase this:

如何避免使用唯一的FB ID并将其替换为普通的索引计数器?

How can I avoid the unique FB id and replace it with a normal index counter?

我的角度服务代码:

        //Save StarBewertung on Mamis
        this.saveStarOnMami = function (data) {
            var ref = new Firebase("https://incandescent-heat-5149.firebaseio.com/contacts")

            var query = ref.orderByChild("id").equalTo(data).on("child_added", function(snapshot) {

                if( snapshot.val() === null ) {
                    /* does not exist */
                } else {
                    //snapshot.ref().update({"phone_fixed": '123'});
                    snapshot.ref().child('rateData').push(1);
                }
            });
        }

是否有一种方法可以将快照作为$ firebase对象获取,对其进行处理,然后使用$ save将其保存到Firebase数据库中?

Is there a way to get the snapshot as an $firebaseobject, manipulate it, and then save it to the Firebase DB with $save?

谢谢...

推荐答案

dbRef.update() dbRef.set().

示例(未经测试)

 var rateSnapshot = snapshot.child('rateData');
 if( rateSnapshot.val() === null ) {  // rateData key does not exist
    rateSnapshot.ref().set([5]);
 } else {
    var rates = rateSnapshot.val(); //should be an array
    rates.push(1); //append new value to the array
    rateSnapshot.ref().set(rates);
 }

这篇关于在firebase对象中创建嵌套数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆