对所有人来说, 我已经打电话给我动态创建复选框并将KeyId推入数组但我得到了上面的错误我已经宣布了类型但是我不明白这个错误了?
options.inputs = [];
//Here we will generate dynamically check-box
for(let i=0; i< data.subCategoriesDtos.length; i++) {
this.subCategoryObject = data.subCategoriesDtos[i];
options.inputs.push({
value: this.subCategoryObject.keyId,
label: this.subCategoryObject.subCategoryName,
type: 'checkbox',
checked: this.showSelectedSubcategory(this.selectedSubcategoryArray[i])
});
}
// Create the alert with the options
let alert = this.alertCtrl.create(options);
alert.present();
&#13;
答案 0 :(得分:1)
执行此操作的正确方法是使用addInput(...)
实例中的Alert
方法添加输入:
addInput(input: AlertInputOptions): Alert; export interface AlertInputOptions { type?: string; name?: string | number; placeholder?: string; value?: string; label?: string; checked?: boolean; disabled?: boolean; id?: string; handler?: Function; min?: string | number; max?: string | number; }
所以使用你的代码看起来像这样:
import { AlertController, Alert, ... } from 'ionic-angular';
// ...
public showAlert(): Promise<any> {
// Create the alert with no options
let alert: Alert = this.alertCtrl.create({});
// Here we will generate dynamically check-box
for(let i=0; i< data.subCategoriesDtos.length; i++) {
this.subCategoryObject = data.subCategoriesDtos[i];
alert.addInput({
value: this.subCategoryObject.keyId,
label: this.subCategoryObject.subCategoryName,
type: 'checkbox',
checked: this.showSelectedSubcategory(this.selectedSubcategoryArray[i])
});
}
return alert.present();
}