json
。当用户单击按钮时,button boolean
在同一页面中显示了不同的数据表单数据URL。当我单击l得到相同的数据时,它不会改变
Loadearlierflights : boolean = true;
async getData() {
const loading = await this.loadingController.create({
message: 'Loading'
});
await loading.present();
/// flights details for today ///
if (this.Loadearlierflights===true) {
this.http.get('xxxxxxx/airport.json?code=bsr', {}, {})
.then(data => {
this.test = JSON.parse(data.data);
const parsed = JSON.parse(data.data);
this.items = parsed.pluginData.schedule.arrivals.data;
loading.dismiss()
console.log(this.items)
}), err=>{
this.test =err
loading.dismiss()
}
/// flights details for yesterday ///
}else if (this.Loadearlierflights===false) {
this.http.get('xxxxxxxx/airport.json?code=bsr&page=-1', {}, {})
.then(data => {
this.test = JSON.parse(data.data);
const parsed = JSON.parse(data.data);
this.items = parsed.pluginData.schedule.arrivals.data;
loading.dismiss()
console.log(this.items)
}), err=>{
this.test =err
loading.dismiss()
}
}
html
<ion-button shape="round" (click)="getData()">load earlier flights</ion-button>
<ion-item *ngFor="let item of items" >
<table>
<tbody>
<tr >
<td >
<div *ngIf="item?.flight.airline.code.icao">
<img src="/{{item?.flight.airline.code.icao}}_logo0.png" (error)="handleImgError($event, item)" class="img-logo">
</div>
<div *ngIf="!item?.flight.airline.code.icao">
item?.flight.airline.name
</div>
</td>
<td text-left>{{item?.flight.identification.number.default}}</td>
<td text-center>{{item?.flight.airport.origin.position.region.city}}</td>
<td text-right>{{item?.flight.time.scheduled.arrival * 1000 | date:"h:mma"}}</td>
</tr>
<tr >
<td > </td>
<td ></td>
<td text-center>{{item?.flight.aircraft.model.code}}</td>
<td text-right [ngClass]='item?.flight.status.generic.status.text |Status'>{{item?.flight.status.generic.status.text|Status}}</td>
</tr>
</tbody>
</table>
</ion-item>
有什么想法吗?
答案 0 :(得分:1)
if-else中有错误
使用If,如下所示
if (this.Loadearlierflights)
or
if (this.Loadearlierflights === true)
如下所示使用else-if
else if (this.Loadearlierflights)
or
else if (this.Loadearlierflights === false)
答案 1 :(得分:0)
也许单击模板以指向新方法:
async getEarlierFlightData() {
this.Loadearlierflights = false;
await this.getData():
this.Loadearlierflights = true;
};
答案 2 :(得分:0)
Loadearlierflights : boolean = true; // should me global
async getData() {
const loading = await this.loadingController.create({
message: 'Loading'
});
await loading.present();
/// flights details for today ///
if (this.Loadearlierflights===true) {
this.http.get('xxxxxxx/airport.json?code=bsr', {}, {})
.then(data => {
this.test = JSON.parse(data.data);
const parsed = JSON.parse(data.data);
this.items = parsed.pluginData.schedule.arrivals.data;
loading.dismiss()
// Added this
this.Loadearlierflights = false;
console.log(this.items)
}), err=>{
this.test =err
loading.dismiss()
}
/// flights details for yesterday ///
}else if (this.Loadearlierflights===false) {
this.http.get('xxxxxxxx/airport.json?code=bsr&page=-1', {}, {})
.then(data => {
this.test = JSON.parse(data.data);
const parsed = JSON.parse(data.data);
this.items = parsed.pluginData.schedule.arrivals.data;
loading.dismiss()
console.log(this.items)
}), err=>{
this.test =err
loading.dismiss()
}
}
让我知道它是否有效。