角显示测验结果?

时间:2019-06-07 05:34:26

标签: javascript angular ionic-framework

尝试制作测验应用程序,但此代码始终仅返回一个对象...我有两个无线电组,并使用(ionSelect) ="radioGroupChange(questionId, answer)"获取值,然后将选定的无线电放置在this.konacno对象数组中,但是此代码始终只放一个...

radioGroupChange(questionId, answer) {
    let answer: { id: number; answer: number } = { id: null, answer: null };
    this.konacno.forEach(element => {
      if (questionId !== element.id) {
        console.log(questionId);
        const index = this.konacno
          .map(function(item) {
            return item.id;
          })
          .indexOf(questionId);
        this.konacno.splice(index, 1);

        answer.id = questionId;
        answer.answer = answer;
        this.konacno.push(odgovor);

        console.log(this.konacno);
        console.log("Nije jednako");
      } else if (questionId === element.id) {
        console.log(questionId);
        const index = this.konacno
          .map(function(item) {
            return item.id;
          })
          .indexOf(questionId);
        this.konacno.splice(index, 1);

        answer.id = questionId;
        answer.answer = answer;
        this.konacno.push(odgovor);

        console.log(this.konacno);
        console.log("Jednako");
      }
    });
  }

0 个答案:

没有答案