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

Sne*_*don 1 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
      };
Run Code Online (Sandbox Code Playgroud)

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

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

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

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


 {{firebaseData}}
Run Code Online (Sandbox Code Playgroud)

数据不会显示,但我有身份验证工作.

Ala*_*los 5

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

添加一个空firebase-documenttemplate

<firebase-document id="mydoc"></firebase-document>
Run Code Online (Sandbox Code Playgroud)

然后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);
  };
Run Code Online (Sandbox Code Playgroud)

至于获取数据firebase-document,检查您实际上是否有数据库中的数据和安全规则,如果您仍然看不到您的数据,那么它可能与此问题有关,请记住polymerfire仍处于预发布状态州