2017-10-17 6 views
0

しばらくの間この問題に固執していましたので、私がしたいのはこれです: フォームを作成するときに、フォームを作成するときに、ユーザのリストと共に電子メールアドレス - このような:Firebaseにネストされたオブジェクトを挿入します

formsById - >フォームID - >のuserId(ユーザーの電子メールアドレスが含まれています)

私は、このような現在のユーザーがフォームのすべてをフィルタリングすることができます。

getFormList() { 
    return firebase.database().ref('/formsByID').orderByChild('userList').startAt(this.userId).endAt(this.userId); 
    } 

私は現在データベースにどのように書き込むのですか:

writeNewForm(formName: string, formDate: string): Promise<any> { 

    // A post entry. 
    let postData = { 
     name: formName, 
     date: formDate, 
     userList: this.userId // I want to nest the email in here 
    }; 

    // Get a key for a new Post. 
    let newPostKey:string = this.formListRef.push().key; 

    // Write the new post's data simultaneously in the posts list and the user's post list. 
    let updates = {}; 
    // write to the users record 
    updates[this.userPath + '/' + newPostKey] = true; // just set this to true be 
    updates[this.formsByIdPath + '/' + newPostKey] = postData; 

    return this.rootRef.update(updates); 
    //return rootRef.update(updates); 

    } 

しかし、自分のユーザーIDで自分のユーザーの電子メールアドレスをネストする方法はわかりません。

助けてください。

答えて

1

私はあなたがこれにあなたのポストのエントリを変更する必要が思う:

// A post entry. 
let postData = { 
    name: formName, 
    date: formDate, 
    userList: [ 
    {email: this.userId} // I want to nest the email in here 
    ] 
}; 

または値の配列を作成します。

// A post entry. 
let postData = { 
    name: formName, 
    date: formDate, 
    userList: [ 
    this.userId // I want to nest the email in here 
    ] 
}; 

その後、あなたは深いパスの更新を行うことができます。

ここではいくつかのより多くの情報を見つけることができます。 https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html

+0

パーフェクト - あなたに感謝 – rhysclay

関連する問題