Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用聚合物&x27;s firebase集合以推送新文档_Firebase_Polymer_Polymer 1.0 - Fatal编程技术网

使用聚合物&x27;s firebase集合以推送新文档

使用聚合物&x27;s firebase集合以推送新文档,firebase,polymer,polymer-1.0,Firebase,Polymer,Polymer 1.0,我在理解如何将新文档推入firebase时遇到问题。我查看了文档,文档中提到了一个名为add(data)的方法,但是我真的不知道如何使用它(因为我的聚合物技能仍然是基本的)。有人可以通过扩展下面的示例元素来展示如何推送新文档吗 <dom-module id="my-position"> <template> <firebase-collection location="my-firebase-app.fi

我在理解如何将新文档推入firebase时遇到问题。我查看了文档,文档中提到了一个名为add(data)的方法,但是我真的不知道如何使用它(因为我的聚合物技能仍然是基本的)。有人可以通过扩展下面的示例元素来展示如何推送新文档吗

<dom-module id="my-position">
  <template>
    <firebase-collection 
                        location="my-firebase-app.firebaseio.com/positions">
    </firebase-collection>

    <template > 
      <input is="iron-input" bind-value="{{value}}"
      placeholder="Your name here...">
    </template>
  </template>
</dom-module>

使用firebase文档和数据绑定将对象“推送”到firebase


这是一个非常简单的例子,说明了如何做到这一点。它基于本文中给出的信息(虽然使用聚合物0.5,但概念非常相似)


提交
(功能(){
聚合物({
是‘我的元素’,
computePositionBJ:函数(){
返回{
姓名:this.name
};
},
特性:{
职位:{
类型:对象,
computed:'computePositionObj(名称)'
},
姓名:{
类型:字符串,
值:“”,
}
},
submitPosition:function(){
此$.ref.add(此位置);
}
});
})();

对象添加到位置。(我为下一部分保留了参考“ref”)

只向位置添加一个键 有你的收藏吗

location="https://<app-name>.firebaseio.com/message/{{id}}"

我不是聚合物专家,但我检查了firebase文档实现,没有推送方法,只有设置和更新。但是,firebase集合有一个名为add的方法(它使用firebase的push方法)。我不认为在这种情况下使用firebase文档是相关的,或者?有没有办法将创建密钥的任务委托给firebase?因为在我下面的示例中,firebase集合会处理这个问题,所以我只需要推送数据。
      var ref = this.$.sparks.add(
        {
          content: 'Hello there',
          by: 'john'
        });
location="https://<app-name>.firebaseio.com/message/{{id}}"
this.id = ref.key();
this.$.COLLECTIONID.query.ref().set(true);