如何阻止 alertController 再次打开
how do I stop alertController from opening a second time
我已经构建了一种将自定义文本插入 ion-select multi 的方法。我使用警报框在 select 数组和输入字段中插入自定义测试,以关闭警报框。一切正常,但在将数据插入输入字段后警告框将再次打开。我如何确保异步 inputCustomValuesMulti 只运行一次。
html
<ion-item class="ion-text-wrap">
<ion-label position="stacked">{{fromItem.Question}}</ion-label>
<ion-select multiple="true" #c (ionChange)="selectChangedMulti(c.value, i)" name="{{fromItem.name}}" [(ngModel)]="fromItem.input">
<ion-select-option *ngFor="let item of importQuestions[i].values" value="{{item.value}}" >{{ item.value }}</ion-select-option>
</ion-select>
</ion-item>
ts
selectChangedMulti(selectedValue: string[], index: string ) {
this.index = index;
if (selectedValue.includes("other")) {
this.inputCustomValuesMulti(selectedValue);
} else {
this.currentValue = selectedValue;
};
};
async inputCustomValuesMulti(selectedValue) {
const inputAlert = await this.alertController.create({
header: 'Enter your custom text:',
inputs: [ { type: 'text', placeholder: 'type in' } ],
buttons: [ { text: 'Cancel' }, { text: 'Ok' } ]
});
await inputAlert.present();
await inputAlert.onDidDismiss().then((data) => {
let customValueName: string = data.data.values[0];
if (customValueName) {
let indexFound = this.importQuestions[this.index].values.findIndex((item: string) => item === customValueName)
if (indexFound === -1) {
this.importQuestions[this.index].values.push({value: customValueName});
let importQuestion = selectedValue;
importQuestion.push(customValueName);
let passData = importQuestion;
let newArray = Array.from(passData);
// inserts new text into input field
this.importQuestions[this.index].input = newArray;
} else {
console.log("else");
};
};
})
};
我最后做的是从传递数据中过滤掉其他数据。
let passData = importQuestion.filter(e => e !== "other");
现在该方法不再在 ionChange 上看到 "other"。
我已经构建了一种将自定义文本插入 ion-select multi 的方法。我使用警报框在 select 数组和输入字段中插入自定义测试,以关闭警报框。一切正常,但在将数据插入输入字段后警告框将再次打开。我如何确保异步 inputCustomValuesMulti 只运行一次。
html
<ion-item class="ion-text-wrap">
<ion-label position="stacked">{{fromItem.Question}}</ion-label>
<ion-select multiple="true" #c (ionChange)="selectChangedMulti(c.value, i)" name="{{fromItem.name}}" [(ngModel)]="fromItem.input">
<ion-select-option *ngFor="let item of importQuestions[i].values" value="{{item.value}}" >{{ item.value }}</ion-select-option>
</ion-select>
</ion-item>
ts
selectChangedMulti(selectedValue: string[], index: string ) {
this.index = index;
if (selectedValue.includes("other")) {
this.inputCustomValuesMulti(selectedValue);
} else {
this.currentValue = selectedValue;
};
};
async inputCustomValuesMulti(selectedValue) {
const inputAlert = await this.alertController.create({
header: 'Enter your custom text:',
inputs: [ { type: 'text', placeholder: 'type in' } ],
buttons: [ { text: 'Cancel' }, { text: 'Ok' } ]
});
await inputAlert.present();
await inputAlert.onDidDismiss().then((data) => {
let customValueName: string = data.data.values[0];
if (customValueName) {
let indexFound = this.importQuestions[this.index].values.findIndex((item: string) => item === customValueName)
if (indexFound === -1) {
this.importQuestions[this.index].values.push({value: customValueName});
let importQuestion = selectedValue;
importQuestion.push(customValueName);
let passData = importQuestion;
let newArray = Array.from(passData);
// inserts new text into input field
this.importQuestions[this.index].input = newArray;
} else {
console.log("else");
};
};
})
};
我最后做的是从传递数据中过滤掉其他数据。
let passData = importQuestion.filter(e => e !== "other");
现在该方法不再在 ionChange 上看到 "other"。