重置(IonChange) - 离子2上的离子选项值



任何人都知道如何重置"离子选择"的"离子选项"值。我有两个离子选择控件,并且我希望我的第一个离子选择(SelectedPlocation)更改离子Change上第二离子选择(SelectedLocation)的值。我能够通过设置null删除所选的选择,但我无法更改所选点的值。有人知道如何重置我的离子选项的价值吗?

我目前正在使用VS2015我的IDE。

html:

<ion-list> 
     <ion-item>
            <ion-label>Parent Location</ion-label>
            <ion-select [(ngModel)]="selectedPLocation" (ionChange)="loadLocation()">
                <ion-option *ngFor="let parentLocation of parentLocations; let i=index" [value]="parentLocation.Key">{{parentLocation.Id}}</ion-option>
            </ion-select>
     </ion-item>
     <ion-item>
            <ion-label>Location</ion-label>
            <ion-select [(ngModel)]="selectedLocation">
                <ion-option id="locationID" *ngFor="let location of locations; let i=index" [value]="location.Key">{{location.Id}}</ion-option>
            </ion-select>
     </ion-item>
</ion-list>

打字稿:

public loadLocation() {
let loader = this.loadingCtrl.create({
    content: "Please wait..."
});
loader.present();
this.selectedLocation = null; //Reset selected value only
this.locations = null; //Tried this but can't seem to reset the values
this.locationService.GetLocations(this.global.getApiUrl(), this.selectedSite, this.selectedPLocation).then(data => {
    loader.dismiss();
    this.locations = data;
}).catch((err) => {
    loader.dismiss();
    let alert = this.alertCtrl.create({
        title: 'Error',
        subTitle: err,
        buttons: ['OK']
    });
    alert.present();
});}

我解决了自己的错误,这是由于我的打字稿代码致电我的Web Service API(GetLocation)。

以前的打字稿代码:

public GetLocations(apiUrl, siteKey, pLocationKey) {
    return new Promise((resolve, reject) => {
        this.http.get(apiUrl + "site/" + siteKey + "/location/" + pLocationKey)
            .map(res => res.json())
            .subscribe(data => {
                this.Locations = data;     //Error Here
                resolve(this.Locations);;  //Error Here
            },
            err => {
                reject(err);
            });
    });
}

正确的打字稿代码:

public GetLocations(apiUrl, siteKey, pLocationKey){
    return new Promise((resolve, reject) => {
        this.http.get(apiUrl + "site/" + siteKey + "/location/" + pLocationKey)
          .map(res => res.json())
          .subscribe(data => {
              resolve(data);     //Corrected
          },
          err =>{
            reject(err);
          });
    });
}

相关内容

  • 没有找到相关文章

最新更新