Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在Firebase中插入嵌套对象_Angular_Ionic Framework_Firebase Realtime Database - Fatal编程技术网

Angular 在Firebase中插入嵌套对象

Angular 在Firebase中插入嵌套对象,angular,ionic-framework,firebase-realtime-database,Angular,Ionic Framework,Firebase Realtime Database,我已经在这个问题上停留了一段时间,所以我想做的是: 创建表单时,将表单连同用户列表及其电子邮件地址一起写入数据库-如下所示: getFormList() { return firebase.database().ref('/formsByID').orderByChild('userList').startAt(this.userId).endAt(this.userId); } formsById->formId->userId(包含用户的电子邮件地址) 然后,我可以按当前用

我已经在这个问题上停留了一段时间,所以我想做的是: 创建表单时,将表单连同用户列表及其电子邮件地址一起写入数据库-如下所示:

  getFormList() {
    return firebase.database().ref('/formsByID').orderByChild('userList').startAt(this.userId).endAt(this.userId);
  }
formsById->formId->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);

  }
writeNewForm(formName:string,formDate:string):承诺{
//一篇博文。
让postData={
姓名:formName,,
日期:formDate,
userList:this.userId//我想将电子邮件嵌套在这里
};
//找一把新职位的钥匙。
让newPostKey:string=this.formListRef.push().key;
//在帖子列表和用户的帖子列表中同时写入新帖子的数据。
让更新={};
//写入用户记录
更新[this.userPath+'/'+newPostKey]=true;//只需将其设置为true即可
更新[this.formsByIdPath+'/'+newPostKey]=postData;
返回此.rootRef.update(更新);
//返回rootRef.update(更新);
}
但我不知道如何将我的用户电子邮件地址嵌套在他们的id下


感谢您的帮助。

我认为您必须将您的博文修改为:

// 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
  ]
};
然后,您可以执行深度路径更新

在这里您可以找到更多信息: