Polymerfire - 在事件发生后创建数据

时间:2016-06-08 19:20:19

标签: polymer firebase-polymer

我使用bower bower安装firebase / polymerfire 的firebase / polymerfire包

如何在触发方法后在数据库中创建一些数据?

文档标记看起来会显示和更新数据。我想,当用户注册时,创建一些供用户使用的数据。

app.signInAnonymously = function() {
        this.error = null;
        this.$.auth.signInAnonymously();
        // add default data for the user template
      };

我如何使用默认的set()或push方法,如普通的SDK?

我怎样才能在JavaScript的事件中调用它?

尝试将路径绑定到我的文档时,如

<firebase-document
 path="/"
 data="{{firebaseData}}">
</firebase-document>


 {{firebaseData}}

数据不会显示,但我的身份验证正在运行。

1 个答案:

答案 0 :(得分:5)

你实际上可以直接使用firebase api,因为firebase-auth已经包含它了,但是如果你想保留基于元素的功能,你可以这样做:

将空firebase-document添加到template

<firebase-document id="mydoc"></firebase-document>

然后在元素中调用其save函数

app.signInAnonymously = function() {
    this.error = null;
    this.$.auth.signInAnonymously();
    // add default data for the user template

    //set path to null somewhere to avoid overwriting data, I recommend doing it here since save's path update is lazy
    this.$.mydoc.path = null;

    //set data to the value to set/push
    this.$.mydoc.data = {/*your data*/};

    //call save, if the second parameter is falsey it'll call push to the first parameter if it's truthy it'll set the data to firstparam/secondparam
    this.$.mydoc.save('path/to/users', userid);
  };

至于使用firebase-document获取数据,请检查您的数据库和安全规则中是否确实有数据,如果仍然看不到您的数据,那么它可能与this issue有关,请执行此操作请记住,polymerfire仍处于释放前状态

相关问题