聚合物:firebase集合总是返回空数组
Polymer: firebase-collection always returns empty array
我尝试使用firebase集合,但无论我尝试什么,我总是收到一个空数组(在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集合时,我会在控制台中得到以下内容
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集合会触发事件: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集合的观察者行为的解释。
相关文章:
- Regex提取URL返回数组的一部分;未定义”;
- 为循环嵌套的Javascript未按预期返回数组
- 从函数中的函数返回数组时出错
- JSON返回数组的奇怪结果
- 如何从NodeJS中的模块返回数组
- 在JS中返回数组的大整数运算
- 从Nodejs中的函数返回数组,并将其发送到ejs视图
- 从函数返回数组
- undercore返回数组中对象的indes,其中单词存在于对象中的句子中
- Yui Get 复选框返回数组而不是布尔值
- 从异步调用返回数组,然后为数组的每个元素返回其他异步调用
- JavaScript闭包和返回数组元素
- 按流星空格键模板中的索引返回数组项
- 从多个文件中推送文本的函数(使用html5文件读取器上传)返回数组
- 我想返回数组
- PHP和Ajax在回调和返回数组中使用foreach循环
- Javascript-如何通过以字符串作为参数返回数组
- 从JSON调用SQL返回数组时出现问题
- Jasmine spyOn使用伪造的返回数组测试功能
- 无法从从sql数据库读取的javascript函数中获取返回数组