Copy a $firebaseObject and save it to a different location

后端 未结 2 409
不思量自难忘°
不思量自难忘° 2021-01-28 05:23

In my application i\'m getting an object from my firebase using $firebaseObject. The use has two options with this object, change it and save the changes in the object or change

2条回答
  •  失恋的感觉
    2021-01-28 05:34

    You can use $value field of $firebaseObject.

    for instance:

    var ref = new Firebase("https://.firebaseio.com");
    var FBObj1 = $firebaseObject(ref.child('child'));
    ref.child('newChild').set(FBObj1.$value);
    

    EDIT:

    Since this only works for primitives, you can try something like this:

    function getObject(obj) {
        var newObj = {};
        for (var key in obj) {
           if (key.indexOf('$') < 0 && obj.hasOwnProperty(key)) {
              newObj[key] = obj[key];
           };
        }
        return newObj;
    }
    

    and use getObject(FBObj1) insetad of FBObj1.$value

提交回复
热议问题