表单提交并将字段附加到Firebase数据库

时间:2018-08-12 14:03:44

标签: html angular firebase firebase-realtime-database

我是Angular5的新手。我正在尝试提交三种不同的表单,它们位于同一网页中,并存储在不同子节点下的firebase数据库中

这些表单记录与课程相关的值,并随着时间的推移上载新的字段值。我正在尝试在同一子节点中将一种形式的字段与其他形式的字段值附加在一起,但不知道要执行它。

例如:在一种形式的字段op1中存在,而在另一种形式的op1中存在,我试图将两种形式的两个值都附加起来,从而在单个子节点下形成一个数组

如何将一个数据字段的值附加到另一个?

主要链接:

代码:

constructor(private db: AngularFireDatabase, private router: Router, private fb: FormBuilder, private dataService: VDataService) {
        this.createForm();
        this.QForm();
        this.DForm();
        this.items = this.db.list('/newCour');
        this.items1 = this.db.list('/newCour1');
        this.items2 = this.db.list('/newCour2');
    }
publish() {
        alert('Pusblished');
        this.item.key = this.vForm.value.name;
        this.item.an1 = this.vForm.value.an1;
        this.item.Com = this.vForm.value.Com;
        this.item.isActive = true;
        this.item.isQCom = false;
        this.item.Score = 0;
        this.item.name = this.vForm.value.name;
        this.item.URL = this.vForm.value.URL;
        this.item.em = this.vForm.value.em;
        this.item.Opa = this.vForm.value.Opa;
        this.item.Opb = this.vForm.value.Optb;
        this.item.Opc = this.vForm.value.Optc;
        this.item.Opd = this.vForm.value.Optd;
        this.item.q1 = this.vForm.value.q1;
        this.item.file = this.vForm.value.file;
        this.test.push(this.item);
        this.db.list(`/newCourse/`).push(this.vForm.value);
        console.log(this.vForm.value.name);
    }

    publishQ() {
        alert('Pusblished');
        this.item1.key = this.Q_Form.value.name;
        this.item1.answer1 = this.Q_Form.value.an1;
        // this.item.isActive = true;
        this.item1.isQCom = false;
        this.item1.Score = 0;
        this.item1.cour_name = this.Q_Form.value.name;
        this.item1.q_name = this.Q_Form.value.q_name;
        this.item1.Opa = this.Q_Form.value.Opta;
        this.item1.Opb = this.Q_Form.value.Optb;
        this.item1.Opc = this.Q_Form.value.Optc;
        this.item1.Opd = this.Q_Form.value.Optd;
        this.item1.q1 = this.Q_Form.value.q1;
        this.test1.push(this.item1);
        this.db.list(`/newCourse1/`).push(this.Q_Form.value);
        console.log(this.Q_Form.value.name);
    }

    publishD() {
        alert('Pusblished');
        this.item.key = this.D_Form.value.name;
        this.item.file = this.D_Form.value.file;
        this.test2.push(this.item);
       // this.items.push(this.test);
        this.db.list(`/newCour2/`).push(this.D_Form.value);
        console.log(this.D_Form.value.name);
    }

0 个答案:

没有答案