加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 在Ionic 2中使用数组进行警报

发布时间:2020-12-17 17:04:42 所属栏目:安全 来源:网络整理
导读:如何使用数组填充警报列表.例如,如果数组有一堆名称. array = [john,dixy,tom,jared]; 我希望弹出警报并显示这些名称,以便从中进行选择. 我正在使用离子2. 解决方法 由于通过使用带有选项的对象创建警报,我们可以使用该对象创建具有数组名称的单选按钮. impo
如何使用数组填充警报列表.例如,如果数组有一堆名称.

array = [john,dixy,tom,jared];

我希望弹出警报并显示这些名称,以便从中进行选择.
我正在使用离子2.

解决方法

由于通过使用带有选项的对象创建警报,我们可以使用该对象创建具有数组名称的单选按钮.

import { Component } from "@angular/core";
import { AlertController } from "ionic-angular/index";

@Component({
  templateUrl:"home.html"
})
export class HomePage {

  private names: Array<string>;

  constructor(private alertCtrl: AlertController) { 
    this.names = [ 'john','dixy','tom','jared']; 
  }

  presentConfirm() {

    // Object with options used to create the alert
    var options = {
      title: 'Choose the name',message: 'Which name do you like?',buttons: [
        {
          text: 'Cancel',role: 'cancel',handler: () => {
            console.log('Cancel clicked');
          }
        },{
          text: 'Ok',handler: data => {
            console.log(data);
          }
        }
      ]
    };

    options.inputs = [];

    // Now we add the radio buttons
    for(let i=0; i< this.names.length; i++) {
      options.inputs.push({ name : 'options',value: this.names[i],label: this.names[i],type: 'radio' });
    }

    // Create the alert with the options
    let alert = this.alertCtrl.create(options);
    alert.present();
  }
}

希望这可以帮助 :)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读