简体   繁体   English

离子选择动态选项

[英]Ionic Select Dynamic Options

I have a dictionary of towns and offices and two Select elements for choosing town and after that office. 我有一有关城镇和办事处的字典 ,还有两个用于选择城镇及其后办事处的Select元素。 After choosing the town from option list the second option element need to show only values for selected town. 从选项列表中选择城镇后,第二个选项元素仅需要显示所选城镇的值。

I am using (ngModelChange) and a method getOffices(officeId) but it doesn't show a thing. 我正在使用(ngModelChange)和方法getOffices(officeId),但未显示任何内容。

How can I solve this problem? 我怎么解决这个问题?

 export class BillingAddressForm { econt: any; offices:any; office: any; constructor( public functions: Functions, public values: Values){ this.econt = { "towns" : { "T1" : "Town1", "T2" : "Town2" }, "offices" : { "T1": { "1070" : "Office1", "1071" : "Office2", "1072" :"Office3"}, "T2": { "6800" : "Office4", "6801" : "Office5", "6802" : "Office6"} } }; } getOffices(officeId){ this.econt.offices = this.form.office[officeId]; this.service.updateOrderReview(this.form) .then((results) => this.OrderReview = results); } } 
  <ion-item> <ion-label> Town </ion-label> <ion-select [(ngModel)]="form.econt" (ngModelChange)="getOffices(form.econt)" name="econt"> <div *ngFor="let field of econt.towns | keys"> <ion-option value="{{field.key}}">{{field.value}} </ion-option> </div> </ion-select> </ion-item> <ion-item> <ion-label> Office </ion-label> <ion-select [(ngModel)]="form.office" name="form.office"> <div *ngFor="let field of offices | keys"> <ion-option value="{{field.key}}">{{field.value}} </ion-option> </div> </ion-select> </ion-item> 

I've found the solution. 我找到了解决方案。 For everyone who needs it: 对于需要它的每个人:

getOffices(officeId) {
    this.office = this.econt.offices[officeId];
    this.service.updateOrderReview(this.form)
        .then((results) => this.OrderReview = results);
}


       <ion-item>
          <ion-label> Town
          </ion-label>
          <ion-select [(ngModel)]="form.econt"  (ngModelChange)="getOffices(form.econt)" name="form.econt">
            <div *ngFor="let field of econt.towns | keys">
              <ion-option value="{{field.key}}">{{field.value}}
              </ion-option>
            </div>
          </ion-select>
        </ion-item>


        <ion-item *ngIf="office">
          <ion-label> Ofice 
          </ion-label>
          <ion-select [(ngModel)]="form.office" name="form.office">
            <div *ngFor="let field of office | keys">
              <ion-option value="{{field.key}}">{{field.value}}
              </ion-option>
            </div>
          </ion-select>
        </ion-item>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM