firebaseにおけるノードの内部リストを追加

サアド・ビット:

私は最近firebaseデータベースに私が欲しいのJSON構造を追加するトラブルを抱えています。私は画像のように私のデータベースに追加の属性を追加しますここでは、画像の説明を入力します。

私が試したorderstReference.child(pid).child("quantity").setValue(orderId); が、値が、私はそれらをリストに追加するようにしたい場所のは、実行するたびに上書きされます。

どのように私はこれを追加することができますか?そして私は私が欲しいものを見つけることができないこれらのものを学ぶための任意の有用なリンクがありますか?

ピーター・ハダッド:

すでにデータを持つノードを持っていて、使用して余分な子を追加したい場合はsetValue()、全ノードを上書きします。このケースでは、使用する必要がありますupdateChildren()

private void writeNewPost(String userId, String username, String title, String body) {
    // Create new post at /user-posts/$userid/$postid and at
    // /posts/$postid simultaneously
    String key = mDatabase.child("posts").push().getKey();
    Post post = new Post(userId, username, title, body);
    Map<String, Object> postValues = post.toMap();

    Map<String, Object> childUpdates = new HashMap<>();
    childUpdates.put("/posts/" + key, postValues);
    childUpdates.put("/user-posts/" + userId + "/" + key, postValues);

    mDatabase.updateChildren(childUpdates);
}

このリンクをチェックしてください:

https://firebase.google.com/docs/database/android/read-and-write#update_specific_fields

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=365870&siteId=1