2017-05-21 14 views
-1

私はちょうどfirebase上にプッシュしている最後のノードのキーを取得しようとしていますが、私のコードは、あなたがlimitToLastを使用する必要がfirebaseは、作成した最後のノードのキーを取得

constructor (props) { 
super(props) 
this.cartFirebase = firebaseApp.database().ref('carts') 


} 

    componentDidMount() { 
    this.cartFirebase.child(DeviceInfo.getUniqueID() + '/items').push({ 
     item: this.props.data.name, 
     qty: 1 
    }) 
    this.cartFirebase.limit(1).on('child_added', function(snapshot) { 
     console.log(snapshot) 
    }) 
    } 

enter image description here

+0

あなたが得るエラーは何ですか? –

+0

こんにちは@FrankvanPuffelenはエラーを追加しました –

+0

エラーメッセージに 'limit()'は関数ではないと書かれています。あなたは 'limitToFirst()'や 'limitToLast()'を探していますか? –

答えて

2

erroring続けます関数。

this.cartFirebase.limitToLast(1).on('child_added', function(childSnapshot) { 

    var snap = childSnapshot.val(); 

}); 
関連する問題