节能新属性将覆盖火力对象 [英] saving new property overwrites firebase object

查看:133
本文介绍了节能新属性将覆盖火力对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在测验使用火力点和角度的工作。在我要救一个新的属性给用户的竞猜结束对象使用该code:

I am working on a quiz using firebase and angular. At the end of the quiz i want to save a new property to the users object using this code:

function saveTopscore() {
    var ref = new Firebase(CONSTANTS.FIREBASE_URL + 'users/' + User.user.$id + '/');
    var userObject = $firebaseObject(ref);
    userObject.topscore = User.totalCorrect;
    userObject.$save().then(function(ref) {
        console.log("worked");
    }, function(error) {
        console.log(error);
    });
}

和它的工作原理,但它也覆盖用户对象的所有属性。所以对象用来装象名称,用户名,电子邮件,密码等,但是当我推最高分数成为该对象的唯一属性。为什么呢?

And it works, but it also overwrite all the properties of the user object. So the object used to hold like a name, username, email, password etc, but when i push the topscore it becomes the only property of the object. Why?

推荐答案

为什么要使用 $ firebaseObject 在这里?如果你三通其绑定到一个角视图才有用。如果您在常规的JavaScript code是,只要坚持到火力地堡的常规的JavaScript SDK。

Why are you using $firebaseObject here? That is only useful if you three-way bind it to an Angular view. If you're in regular JavaScript code, just stick to Firebase's regular JavaScript SDK.

在这种情况下,只是做:

In this case, just do:

ref.update({ topscore: User.totalCorrect });

这篇关于节能新属性将覆盖火力对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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