簡體   English   中英

聚合物:firebase-collection始終返回空數組

[英]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收集的觀察者行為的解釋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM