从多个复选框获取字符串形式的值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从多个复选框获取字符串形式的值相关的知识,希望对你有一定的参考价值。
我知道这个问题已被多次问及回答,但似乎无法弄清楚如何将其实现到我的应用程序中。我对Ionic和Angular还是很陌生。
我有一个下拉复选框列表,用户可以在其中选择一个或多个答案。我需要选择要作为字符串发送的值。提交表单时,出现此错误。无论是一个还是多个答案,都会发生此错误。
<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);
});
});
}
在模型中,firstQuestionAnswer是一个字符串。我不确定其他人还需要回答什么,所以请让我知道,我会尽力而为。
答案
您可以将数组转换为字符串并在可能的情况下将其传递
在这里:
this.selectedItem=["Banana", "Orange", "Apple", "Mango"];
this.selectedItem=this.selectedItem.toString();
以上是关于从多个复选框获取字符串形式的值的主要内容,如果未能解决你的问题,请参考以下文章