html - 添加“全选”按钮以进行离子选择
问题描述
我正在使用 ionic 4,我想通过 interfaceOptions 在离子选择上设置自定义按钮
HTML
<ion-item>
<ion-label>Lines</ion-label>
<ion-select multiple="true" [(ngModel)]="SelectedLines" [interfaceOptions]="customAlertOptions">
<ion-select-option [value]="line" *ngFor="let line of Lines">{{linea.Name}}</ion-select-option>
</ion-select>
</ion-item>
TS
customAlertOptions: any = {
buttons: [
{
text: 'Select All',
handler: (blah) => {
console.log('Select All Clicked');
},
{
text: 'No',
handler: (blah) => {
console.log('Confirm Cancel: blah');
}
}, {
text: 'Okay',
handler: () => {
console.log('Confirm Okay');
}
}
]
};
但是,仅显示默认按钮(确定和取消)
医生说应该可以
https://ionicframework.com/docs/api/select
我可以看到以前版本的 Ionic 已经报告了这一点
是否有可能在 Ionic 4 上进行这项工作?有解决方法吗?
编辑:我尝试使用 PopOver 界面,结果相同
解决方案
从我所见,您尝试做的事情是不可能的。
文档实际上只说您可以设置按钮文本:
默认情况下,警报有两个按钮:
Cancel
和OK
。可以使用cancelText
和okText
属性自定义每个按钮的文本。
并不是说可以自定义按钮。
您可以传入,interfaceOptions
但稍后会被默认按钮集覆盖:
代码如下所示:
const alertOpts: AlertOptions = {
mode,
...interfaceOptions,
header: interfaceOptions.header ? interfaceOptions.header : labelText,
inputs: this.createAlertInputs(this.childOpts, inputType),
buttons: [
{
text: this.cancelText,
role: 'cancel',
handler: () => {
this.ionCancel.emit();
}
},
{
text: this.okText,
handler: (selectedValues: any) => {
this.value = selectedValues;
}
}
],
cssClass: ['select-alert', interfaceOptions.cssClass,
(this.multiple ? 'multiple-select-alert' : 'single-select-alert')]
};
return alertController.create(alertOpts);
如您所见...interfaceOptions,
,在开始时传入,然后按钮设置为默认值,唯一的自定义选项是确定或取消文本。
推荐阅读
- java - 如何限制rest api方法的列表参数中的值
- javascript - 回调无效,回调前函数仍执行
- apache-fop - Apache-FOP 2.3 版本是否支持 EPS 图像?
- asp.net-core - 无法跟踪实体类型“Bot”的实例,因为另一个实例具有相同的 {'Id'} 键值
- vue.js - 从 vuex 操作中调用时,应该在哪里处理来自 REST API 调用的错误?
- php - 在 PHP 中按特定列排序表的问题
- amazon-web-services - AWS IoT 和 SQS:重定向到 AWS 中的 SQS 时如何获取 IoT 主题并完成 JSON 有效负载
- vba - 与参数值相关的多个 OR 条件
- java - Azure 上的 Liquibase 3.7.0 - 意外的 Liquibase 异常:找不到 LockService
- android - Android Google maps-v2 以前的折线未删除