【问题标题】:Data passed by ionChange using ion-select does not get passed as input to the api - IonicionChange 使用 ion-select 传递的数据不会作为输入传递给 api - Ionic
【发布时间】:2018-10-29 15:03:51
【问题描述】:

大家好,我正在开发这个送餐应用程序,用户在 ion-select 组件中输入一个 Delivery Circle,他/她会停留在那里,然后我通过获取 Delivery Circle 的值来触发另一个 api(例如 1 ,2,3...等)在另一个离子选择组件中,该组件是他/她停留的区域或地点,并根据所选的递送圈填充离子选择。

在这里我可以传递传递圈的价值,我已经安慰了这个价值和它的罚款。但是当我尝试将 id 作为数据传递给下一个 api 时,它会变为空白......

这是我的 html 文件

<ion-content padding class="bgpage">
<div class = "col-md-6">
<ion-item>
  <ion-label>Delivery Circle</ion-label>
  <ion-select [(ngModel)]="data" (ionChange) = "delAreaCircle(del_cir)">
    <ion-option  *ngFor = "let data of circleResponse" [value]="data['del_c_id']">{{data['del_c_name']}}</ion-option>
  </ion-select>
</ion-item>
</div>
<ion-item>
  <ion-label>Area / Near by Locality</ion-label>
  <ion-select [(ngModel)]="area_loc">
    <ion-option value="1">St. cruz</ion-option>
  </ion-select>
</ion-item>
</ion-content>

这是我的 .ts 文件函数。

delCircle(){
let circleUrl = 'http://url/folder/filename.php';
let circleData: Observable<any> = this.http.get(circleUrl);
circleData.subscribe( data => { this.circleResponse = data.json();
this.circleResponse = this.circleResponse; 
console.log(this.circleResponse);

});
}

delAreaCircle(id){
let headers = new Headers();
headers.append('Content-Type', 'application/json');

console.log("Inside Location Cordinates",id)
this.del_id = id;
let options = new RequestOptions({ headers: headers });
let circlePassData = {"del_c_id":this.del_id}
console.log("dataPassed",this.circlePassData);
this.http.post('http://url/folder/filename.php', circlePassData , options)
.subscribe(data => {this.circlePassDataFetch = data.json();

console.log("dataReached",this.circlePassDataFetch);

});  
}

【问题讨论】:

  • 使用 ngModelChange 代替 ionChange。
  • 是的,我做到了.. 但没有运气@Naqeeb

标签: ionic-framework ion-select


【解决方案1】:

将 (ionChange) 函数中的参数更改为 $event。这会将所选选项的值传递给您的函数。

<ion-content padding class="bgpage">
<div class = "col-md-6">
<ion-item>
  <ion-label>Delivery Circle</ion-label>
  <ion-select [(ngModel)]="data" (ionChange) = "delAreaCircle($event)">
    <ion-option  *ngFor = "let data of circleResponse" [value]="data['del_c_id']">{{data['del_c_name']}}</ion-option>
  </ion-select>
</ion-item>
</div>
<ion-item>
  <ion-label>Area / Near by Locality</ion-label>
  <ion-select [(ngModel)]="area_loc">
    <ion-option value="1">St. cruz</ion-option>
  </ion-select>
</ion-item>
</ion-content>

【讨论】:

  • 完美@Jonathan。万分感谢! :)
猜你喜欢
  • 2021-02-09
  • 2017-07-16
  • 2016-03-24
  • 1970-01-01
  • 2023-04-06
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 2023-03-05
相关资源
最近更新 更多