0

I try to use firebase-collection, but whatever I try I always receive an empty array (in firebase I have a couple of entries)

<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>

the firebase-document element works! Any suggestions why I receive an empty list ?

Furthermore, when I manually add a new item to the firebase-collection I get the following in the console

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}

And nothing happens in firebase :(

4

1 回答 1

1

不要使用观察者。当我玩的时候,我发现观察者只会触发一次:在第一次加载时。我不能告诉你为什么。

幸运的是,当数据更改时,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 观察者行为的一些解释。

于 2015-11-13T18:21:15.523 回答