0

我的页面上有两个下拉菜单。

一个是Country,另一个是City。两者都具有"Please Select"默认值。

当用户更改Country相应城市中的值时,会正确填充City.

但是,当用户edit record从页面上的网格中按下图标时,相应的值会填充到Country下拉列表中,但City下拉列表值始终保持为"Please Select".

public onCountryChangeEvent(slectedCountryId): void {
        this.populateCityListByCountry(slectedCountryId);
  }

private populateCityListByCountry(countryId: Number) {
    
   var city: City = new City();
   city.cityId = AppConstants.PLEASE_SELECT_VAL;
   city.cityName = AppConstants.PLEASE_SELECT_STR;

  const cityCombo: FormControl = (<any>this.myForm).controls.cityId;
  if(AppUtility.isEmpty(countryId)){
      this.cityList=[];
      this.cityList.unshift(city);
      cityCombo.reset();
  } else {
      this.listingService.getCityListByCountry(countryId)
            .subscribe(
            restData => { 
        if(AppUtility.isEmpty(restData)){
           this.cityList=[];
           this.cityId=null;
           this.city=null;         
        }
        else{
          this.cityList = restData;
           if(!AppUtility.isEmptyArray(this.cityList)){
             if(!this.isEditing){
                this.cityId = this.cityList[0].cityId;              
               this.city=this.cityList[0].cityName;
              }
     
           }
           
        }   
        this.cityList.unshift(city);
       },
      error => {this.errorMessage = <any>error;},
      ()=> {  
        cityCombo.reset();                        
          }    
      );
  }
}
<label for="countryId" class="col-md-3 col-xs-12 form-control-label text-md-right">Country</label>
<div class="col-md-8 col-xs-12">
  <wj-combo-box id="countryId" tabindex="3" formControlName="countryId" class="form-control" [isEditable]="false" [itemsSource]="countryList" 
									displayMemberPath="countryName" (ngModelChange)="onCountryChangeEvent($event)" selectedValuePath="countryId" [(ngModel)]="countryId"
									required></wj-combo-box>
								</div>

<wj-combo-box id="cityId" tabindex="4" formControlName="cityId" class="form-control" [isEditable]="false" [itemsSource]="cityList"
										displayMemberPath="cityName" selectedValuePath="cityId" [(ngModel)]="cityId" required></wj-combo-box>

4

0 回答 0