任何使用 firebase-document 的例子

Any example using firebase-document

我需要使用 firebase-document 从 Firebase 获取数据。在 收到响应负载后,我需要进一步处理数据 。我该怎么做?

I read the documentation here, but there are no examples。我看到有一个名为 transactionsComplete 的 属性,但同样没有示例。由于它是 promise,我不确定如何实现它。

有人可以提供一个工作代码示例,说明如何使用 firebase-document 的属性或方法来处理请求返回的数据以及 after 交易是完成了吗?

<firebase-document
    id="doc"
    app-name="my-app">
</firebase-document>
<script>
  _userChanged: function(u) {
    if(u) {
      var doc = this.$.doc;
      var path = [ 'users' , u.uid ].join('/');
      doc.path = path; // this should send a request for data
      // but how do I ensure to process what is returned
      // after and only after it comes back?
    }                   
  },
</script>

将一个对象绑定到 属性 data="{{object}}" 然后你可以添加一个 observer 或计算 属性 这将 return 最终值

<firebase-document
  path="/users/{{userId}}/notes/{{noteId}}"
  data="{{noteData}}">
</firebase-document>

使用firebase-focument方法getStoredValue(path);(ES6风格)

  this.$.doc.getStoredValue(path)
    .then((response) => {
      console.log(response);
    });
<!-- setup firebase-document (node) -->
<firebase-document
  path="/dummy"
  data="{{dummy}}">
</firebase-document>

<paper-input 
  id="dummy"
  name="dummy"
  label="Dummy Text"
  value={{dummy.text}}>
</paper-input>

或者您可以在 javascript function 中使用 this.dummy 来访问变量。

由于使用了 Polymer 的数据绑定,值将被更新到 firebase。