从多个复选框中获取值作为字符串

Getting values as a string from multiple checkbox

我知道这个问题已被多次询问和回答,但我似乎无法弄清楚如何将它们实施到我的应用程序中。我对 Ionic 和 Angular.

还很陌生

我有一个下拉复选框列表,用户可以在其中 select 一个或多个答案。我需要将值 selected 作为字符串发送。提交表单时,出现此错误。无论是一个还是多个答案都会出现此错误。

HTML

    <ion-item>
      <ion-label stacked>1. Type of Incident or Observation</ion-label>
      <ion-select multiple="true" formControlName="firstQuestionAnswer" required [(ngModel)]="stopCardRequest.firstQuestionAnswer">
        <ion-option *ngFor="let firstQuestionAnswer of firstQuestionOptions" value="{{firstQuestionAnswer.value}}">{{firstQuestionAnswer.name}}</ion-option>
      </ion-select>
    </ion-item>

TS

  firstQuestionOptions = [
    { name: "Near Miss", value: "Near Miss" },
    { name: "First Aid", value: "First Aid" },
    { name: "Medical Beyond First Aid (HSE will conduct investigation)", value: "Medical Beyond First Aid (HSE will conduct investigation)" },
    { name: "Lost Time", value: "Lost Time" },
    { name: "Environmental (spills / releases)" ,value: "Environmental (spills / releases)" },
    { name: "Security", value: "Security" },
    { name: "Vehicle / Equipment Incident", value: "Vehicle / Equipment Incident" },
    { name: "Fire", value: "Fire"  },
    { name: "Illness", value: "Illness" },
    { name: "General Observation", value: "General Observation" }
  ];

  public submitRequest(values) {
    this.showLoading().then(() => {
      this.stopCardProvider.save(this.stopCardRequest).subscribe(
        () => {
          this.logger.info("Stop Card sent");
          this.alertProvider.showSubmission();
          this.stopCardForm.reset();
          // Dismiss loading overlay.
          this.loading.dismiss();
        },
        error => {
          // Dismiss loading overlay.
          this.loading.dismiss();
          this.alertProvider.showError(error);
        });
    });
  }

在模型中,第一个问题答案是一个字符串。我不确定还有什么人需要回答这个问题,所以请告诉我,我会尽我所能。

您可以将数组转换为字符串并在任何可能的时候传递它

例如:

this.selectedItem=["Banana", "Orange", "Apple", "Mango"]; this.selectedItem=this.selectedItem.toString();