2015-11-08 42 views
0

我嘗試使用firebase-collection,但無論我嘗試,我總是收到一個空數組(以火力點我有幾個條目)聚合物:火力收集總是返回空數組

<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元素的作品!任何建議,爲什麼我收到一個空的列表?

而且,當我手動添加新項火力收集我在控制檯中

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} 

並沒有什麼下面發生在火力:(

+0

嘗試使用firebase-document而不是firebase-collection – Srik

+0

firebase-document返回一個對象。 Firebase集合用於陣列,所以這應該工作 –

回答

1

不要使用觀察者。當我打的時候,我發現,觀察者永遠只能觸發一次:關於第一個負載,我不能告訴你爲什麼

幸運的是,火力收集觸發事件時,數據的變化: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

希望這會有所幫助,我會繼續尋找在觀察者一些解釋行爲爲火力點收集。

+0

感謝您指出這一點,這就是我需要的! –