2016-05-15 6 views
1

私はfirebaseに以下の構造を持っており、私はユーザーのクライアントの名前を取得しようとしています。2つ以上のfirebase要素をどのように入れ子にすることができますか?

Firebase structure

このコードは、任意の名前を表示しない、それは私が二firebase要素が非同期的にそれを持つ前にclient.__firebaseKey__を使用しているため、私の問題であることを推測する、でもクロムインスペクタをクラッシュします。

Polymerのドキュメントには、要素を同期的にレンダリングする方法を知らせるpageがありますが、動作しませんでした。

  <template is="dom-bind"> 
       <firebase-collection 
       location="https://periodiza.firebaseio.com/user/-KHkue7mLaVe1b_bO3Zb/clients" 
       data="{{clients}}" 
       ></firebase-collection> 
       <template is="dom-repeat" items="[[clients]]" as="client"> 
       <firebase-document 
        location="https://periodiza.firebaseio.com/user/{{client.__firebaseKey__}}/name" 
        data="{{clientName}}" 
       ></firebase-document> 
       <a class="paper-item-link"> 
        <paper-item raised>[[clientName]]</paper-item> 
       </a> 
       </template> 
      </template> 
+0

firebase_authからまだログインしていませんか?あなたのコレクションにアクセスできません。 – getbuckts

+0

これは一般公開されているかどうかはわかりませんが、FirebaseサイトではなくAPI経由でアクセスできるはずです。 –

+0

新しいFirebase APIが[複数のログイン方法](https://firebase.google.com/docs/auth/web/account-linking)をサポートしているので、データベースが少し変わります。 –

答えて

1

私はそれを行うために管理が、私はfirebase-elementの何を使用していないしていないとして、それが最善の解決策ではないと思います。ローカルのリファレンスFirebase()をローカルに宣言しているので、さらに問題が発生する可能性があり、まだログオンしているユーザーを取得する必要があります。私は私のカスタム要素を使用することにしました

<link rel="import" href="../../bower_components/polymer/polymer.html"> 
<link rel="import" href="../../bower_components/firebase-element/firebase.html"> 

<dom-module id="client-list"> 
    <template> 
    <template is="dom-repeat" items="{{clients}}"> 
     <a class="paper-item-link"> 
     <paper-item raised>cliente {{item.name}}</paper-item> 
     </a> 
    </template> 
    </template> 
    <script> 
    function updateClients(context){ 
     var base = new Firebase("https//periodiza.firebaseio.com/user") 

     base.child("-KHkue7mLaVe1b_bO3Zb").child("clients").on("value", snapshot => { 
     context.clients = [] 
     for(key in snapshot.val()){ 
      base.child(key).once("value", snapshot => { 
      context.push('clients', snapshot.val()) 
      }) 
      base.child(key).once("child_changed", snapshot => { 
      updateClients(context) 
      }) 
     } 
     }) 
    } 

    Polymer({ 
     is: 'client-list', 

     ready: function(){ updateClients(this) } 
    }) 
    </script> 
</dom-module> 

、私が提供firebase要素は、このようなドキュメントを結合するために使用されることを意図しているかはわかりません。

関連する問題