聚合物:firebase-collection 总是 returns 空数组
Polymer: firebase-collection always returns empty array
我尝试使用 firebase-collection,但无论我尝试什么,我总是收到一个空数组(在 firebase 中我有几个条目)
<dom-module id="bar-foo">
<template>
<firebase-collection
id="barFoo"
location="https://bar-foo.firebaseio.com/items"
data="{{items}}"></firebase-collection>
<firebase-document location="https://bar-foo.firebaseio.com/item"
data="{{item}}"></firebase-document>
</template>
<script>
class BarFoo {
beforeRegister() {
this.is = 'bar-foo';
this.properties = {
items: {
notify: true,
observer: 'updated',
type: Array
}
}
}
updated(newList) {
// newList === this.items === []
...
}
}
Polymer(BarFoo);
</script>
</dom-module>
firebase-document
元素有效!为什么我收到一个空列表有什么建议吗?
此外,当我手动将新项目添加到 firebase-collection 时,我在控制台中得到以下信息
this.$.barfoo.add('aaaa')
firebase-query-behavior.html:182 Adding new item to collection with value: aaaa
firebase-query-behavior.html:182 Firebase Event: "child_added" aaaa null
U {k: Yh, path: L, n: ae, lc: false}
而且在 firebase 中什么也没有发生:(
不要使用观察者。当我四处游玩时,我发现观察者只会开火一次:在第一次加载时。我不能告诉你为什么。
幸运的是,firebase-collection 在数据更改时触发事件:https://github.com/GoogleWebComponents/firebase-element/issues/86
添加事件侦听器而不是 属性 观察器:
this.listeners = {
'barFoo.firebase-value': 'updated'
}
这个来自 PolymerLabs 的例子使用了事件侦听器而不是观察器:
https://github.com/PolymerLabs/todo-list/blob/master/app/elements/todo-data/todo-data.html
希望这对您有所帮助,我会继续寻找有关 firebase-collection 的观察者行为的解释。
我尝试使用 firebase-collection,但无论我尝试什么,我总是收到一个空数组(在 firebase 中我有几个条目)
<dom-module id="bar-foo">
<template>
<firebase-collection
id="barFoo"
location="https://bar-foo.firebaseio.com/items"
data="{{items}}"></firebase-collection>
<firebase-document location="https://bar-foo.firebaseio.com/item"
data="{{item}}"></firebase-document>
</template>
<script>
class BarFoo {
beforeRegister() {
this.is = 'bar-foo';
this.properties = {
items: {
notify: true,
observer: 'updated',
type: Array
}
}
}
updated(newList) {
// newList === this.items === []
...
}
}
Polymer(BarFoo);
</script>
</dom-module>
firebase-document
元素有效!为什么我收到一个空列表有什么建议吗?
此外,当我手动将新项目添加到 firebase-collection 时,我在控制台中得到以下信息
this.$.barfoo.add('aaaa')
firebase-query-behavior.html:182 Adding new item to collection with value: aaaa
firebase-query-behavior.html:182 Firebase Event: "child_added" aaaa null
U {k: Yh, path: L, n: ae, lc: false}
而且在 firebase 中什么也没有发生:(
不要使用观察者。当我四处游玩时,我发现观察者只会开火一次:在第一次加载时。我不能告诉你为什么。
幸运的是,firebase-collection 在数据更改时触发事件:https://github.com/GoogleWebComponents/firebase-element/issues/86
添加事件侦听器而不是 属性 观察器:
this.listeners = {
'barFoo.firebase-value': 'updated'
}
这个来自 PolymerLabs 的例子使用了事件侦听器而不是观察器: https://github.com/PolymerLabs/todo-list/blob/master/app/elements/todo-data/todo-data.html
希望这对您有所帮助,我会继续寻找有关 firebase-collection 的观察者行为的解释。