将 Firebase 对象移动/复制到另一个子节点

Noe*_*own 4 angularjs firebase angularfire ionic-framework

我在 firebase 中有一个用户对象,我需要移动到同一棵树上的另一个子节点。

结构是这样的:

users -> male   -> uid -> ......KVPs..objects...etc
      -> female -> uid -> ......KVPs..objects...etc
Run Code Online (Sandbox Code Playgroud)

由于应用程序的性质,我需要将用户按性别分开。如果用户更改了他们的性别,我想将他们的所有详细信息移动到该选定的性别。

我尝试使用 AngularFire (firebaseObject),但是当我尝试在 firebase 中设置它时,由于对象中存在键,它会引发错误。我尝试使用 JSON.stringify、angular.toJSON 剥离键,但我没有任何运气!!

我想知道是否有更清洁或推荐的方法来做到这一点?感谢如果有人有任何指示或可以提供帮助。

非常感谢,诺埃尔

Noe*_*own 7

这实际上很容易

    // firebase ref
    desc.ref1 = new Firebase(desc.userRef+'/'+desc.oldGender+'/'+uid);
    desc.ref2 = new Firebase(desc.userRef+'/'+desc.gender+'/'+uid);

    desc.ref1.on("value", function(snapshot) {
        console.log(snapshot.val());

        desc.ref2.set(snapshot.val());

    }, function (errorObject) {
        console.log("The read failed: " + errorObject.code);
    });
Run Code Online (Sandbox Code Playgroud)