嵌套对象在firebase中没有保存

时间:2015-11-21 19:09:43

标签: angularjs firebase

所以我在我的代码中有这个firebase对象,我试图保存:

{"Education/schoolName": "RIT", 
"Education/major": "Computer Science", 
"Education/startYear": "November 25, 2015", 
"Education/endYear": "November 30, 2015"}

尝试运行我的代码时出现此错误:

Error: Firebase.update failed: First argument  contains an invalid key ("Education/schoolName") in property 'users.235642888'.  Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"
at Error (native)
at https://cdn.firebase.com/js/client/2.2.4/firebase.js:129:18
at hb (https://cdn.firebase.com/js/client/2.2.4/firebase.js:20:550)
at Sf (https://cdn.firebase.com/js/client/2.2.4/firebase.js:128:424)
at Rf (https://cdn.firebase.com/js/client/2.2.4/firebase.js:127:408)
at Tf (https://cdn.firebase.com/js/client/2.2.4/firebase.js:130:245)
at U.update (https://cdn.firebase.com/js/client/2.2.4/firebase.js:245:369)
at http://localhost:63342/startupadda/build/src/common/userData.js:59:32
at new Q (http://localhost:63342/startupadda/build/vendor/angular/angular.js:13491:5)
at Q (http://localhost:63342/startupadda/build/vendor/angular/angular.js:13478:14)

我的角度服务看起来像这样:

function saveUserDetails(email,object){
        var hashedEmail = Utilities.getHashCode(email);
        object = angular.fromJson(angular.toJson(object));
        object = Utilities.flattenObject(object,{});
        var userRef = ref.child(hashedEmail);

        console.log("Saving object ",object);
        return $q(function(resolve,reject){
            return userRef.update(object, function(error){
                if(error){
                    reject(error);
                }else{
                    resolve("Updated successfully!");
                }
            });
        });
    }

但是当我在Chrome控制台中尝试做同样的事情时:

ref.update({"Education/schoolName": "RIT", 
"Education/major": "Computer Science", 
"Education/startYear": "November 25, 2015", 
"Education/endYear": "November 30, 2015"});

该对象在firebase中成功保存。我不知道为什么通过我的代码没有成功,因为在两种情况下对象都保持不变。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

您使用的是Firebase客户端库的过时版本,该版本不支持深层路径更新。截至今天,2015年11月21日的最新版本是2.3.2。

https://www.firebase.com/docs/web/changelog.html