使用 Polymer 的 firebase-collection 推送新文档
Using Polymer's firebase-collection to push a new document
我无法理解如何将新文档推送到 Firebase。我查看了文档 here,它提到了一个名为 add(data) 的方法,但是我真的不知道如何使用它(因为我的 Polymer 技能仍然很基础)。有人可以通过扩展下面的示例元素来展示如何推送新文档吗?
<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-document 和数据绑定 'pushs' 对象到 firebase。
https://elements.polymer-project.org/elements/firebase-element?active=firebase-document
这是一个非常简单的例子,展示了如何做到这一点。它基于此video中给出的信息(虽然使用聚合物0.5,但概念非常相似)。
<dom-module id="my-elem">
<template>
<firebase-collection id="ref"
location="https://my-firbase-app/positions/">
</firebase-collection>
<form id="createPosition">
<input is="iron-input" bind-value="{{name}}" type="" id="name" placeholder="name here...">
</form>
<paper-button on-click="submitPosition">submit</paper-button>
</template>
<script>
(function () {
Polymer({
is: 'my-elem',
computePositionObj: function(){
return {
name: this.name
};
},
properties: {
position: {
type: Object,
computed: 'computePositionObj(name)'
},
name: {
type: String,
value: '',
}
},
submitPosition: function() {
this.$.ref.add(this.position);
}
});
})();
</script>
</dom-module>
将 object 添加到某个位置。 (我为下一部分保留参考'ref')
var ref = this.$.sparks.add(
{
content: 'Hello there',
by: 'john'
});
只添加一个 key 到一个位置
有你的collection
location="https://<app-name>.firebaseio.com/message/{{id}}"
当您想添加一个键作为 child 时,只需执行
this.id = ref.key();
this.$.COLLECTIONID.query.ref().set(true);
我无法理解如何将新文档推送到 Firebase。我查看了文档 here,它提到了一个名为 add(data) 的方法,但是我真的不知道如何使用它(因为我的 Polymer 技能仍然很基础)。有人可以通过扩展下面的示例元素来展示如何推送新文档吗?
<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-document 和数据绑定 'pushs' 对象到 firebase。
https://elements.polymer-project.org/elements/firebase-element?active=firebase-document
这是一个非常简单的例子,展示了如何做到这一点。它基于此video中给出的信息(虽然使用聚合物0.5,但概念非常相似)。
<dom-module id="my-elem">
<template>
<firebase-collection id="ref"
location="https://my-firbase-app/positions/">
</firebase-collection>
<form id="createPosition">
<input is="iron-input" bind-value="{{name}}" type="" id="name" placeholder="name here...">
</form>
<paper-button on-click="submitPosition">submit</paper-button>
</template>
<script>
(function () {
Polymer({
is: 'my-elem',
computePositionObj: function(){
return {
name: this.name
};
},
properties: {
position: {
type: Object,
computed: 'computePositionObj(name)'
},
name: {
type: String,
value: '',
}
},
submitPosition: function() {
this.$.ref.add(this.position);
}
});
})();
</script>
</dom-module>
将 object 添加到某个位置。 (我为下一部分保留参考'ref')
var ref = this.$.sparks.add(
{
content: 'Hello there',
by: 'john'
});
只添加一个 key 到一个位置 有你的collection
location="https://<app-name>.firebaseio.com/message/{{id}}"
当您想添加一个键作为 child 时,只需执行
this.id = ref.key();
this.$.COLLECTIONID.query.ref().set(true);