【问题标题】:Save Alert text input into database from ionic alert从离子警报将警报文本输入保存到数据库中
【发布时间】:2018-08-06 23:34:24
【问题描述】:

我创建了一个离子警报来拒绝请求。我希望用户在点击确认之前输入拒绝请求的原因。然后我想将此数据保存到我的数据库中并设置一个方法(declineRequest)来执行此操作。

该方法正在拒绝请求。问题是如何将警报“备注”输入字段保存到数据库中,以及如何确保仅在单击“确认”时才运行拒绝请求方法。

代码如下:

HTML:

<ion-list>
    <ion-card *ngFor="let r of requests; let i = index">
      <ion-item>
      <h2>{{r.userId}}</h2>
      <p>{{r.requestDetail}}</p>
      <p>{{r.fromDateTime}} to {{r.toDateTime}}</p>
      <p>{{r.type}}</p>
      </ion-item>
      <ion-card-content>
            <button class="approve" ion-button icon-left color="secondary" (click)="approveAlert(r.id)">
              <ion-icon name="checkmark"></ion-icon>
              Approve
            </button>
            <button class="decline" ion-button icon-left color="danger" (click)="declineAlert(r.id)">
              <ion-icon name="close"></ion-icon>
              Decline
            </button>
      </ion-card-content>
    </ion-card> 
  </ion-list> 

TS:

declineAlert(requestId) {
const alert = this.alertCtrl.create({
  title: 'Confirm Request Declined',
  subTitle: 'Notes:',
  inputs: [
    {
      name: "Note",
      type: "text",
      placeholder: 'Please enter reasons'
    }],
  buttons: [ { text:"Cancel"
  },
  { text: "Confirm",      
  handler: data => {
    console.log(JSON.stringify(data)); 
    console.log(data.Note);
  }
  }],
  cssClass: 'alertCustomCss'
});
alert.present();
console.log(requestId);
let notes = Note;
this.declineRequest(requestId, notes);
}

我尝试了不同的方法,但似乎无法从拒绝“注释”中获取文本以保存。

任何帮助将不胜感激。

【问题讨论】:

    标签: javascript typescript ionic-framework ionic3 alert


    【解决方案1】:

    正如 Keval 指出的那样,您只需要像这样在处理程序中使用您的方法:

    declineAlert(requestId) {
      const alert = this.alertCtrl.create({
      title: 'Confirm Request Declined',
      subTitle: 'Notes:',
      inputs: [
        {
          name: "Note",
          type: "text",
          placeholder: 'Please enter reasons'
        }],
      buttons: [ { text:"Cancel"
      },
      { text: "Confirm",      
      handler: data => {
          this.declineRequest(requestId, data.Note);
          // additional steps like pop() page etc
        }
      }],
        cssClass: 'alertCustomCss'
      });
      alert.present();
    }
    

    【讨论】:

      【解决方案2】:

      试试我的工作代码

        let alert = this.alertCtrl.create({
        title: 'Confirm Request Declined',
        inputs: [
          {
            type: 'textarea',
            name: 'Message',
            placeholder: 'Please enter reasons',
          },
        ],
        buttons: [
          {
            text: 'Yes',          
            handler: data => {           
              var message = data.Message;
             //Here is Api call
            }
          },
          {
            text: 'No',          
            role: 'cancel',
            handler: data => {           
              var message = data.Message;
              //Your logic
            }
          }
        ]
      });
      alert.present();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-23
        • 2018-05-23
        • 2018-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多