2017-08-01 20 views
-1
<div *ngFor="let filterItem of fields[0].searchParameters; let i = index" class="custom"> 
    <label>{{filterItem.fieldlabel}}</label> 
    <div class="form-group"> 
     <span [ngSwitch]="filterItem.fieldtype"> 
      <input ngDefaultControl [focusOnInit]="i" *ngSwitchCase="'INPUT'" [ngModel]="selectedDevice" [ngModelOptions]="{standalone: true}" class="form-control-full" (change)="changeFilterValue(filterItem.value1)" (keydown)="keyDownFunction($event)"/> 
      <select *ngSwitchCase="'LOV'" class="form-control custom-select" type="text" [(ngModel)]="filterItem.value1" [ngModelOptions]="{standalone: true}" (change)="changeFilterValue(filterItem)"> 
       <option value="" ></option> 
       <option *ngFor="let value of filterItem.values" [(value)]="value.code" required>{{value.displayName}}</option> 
      </select> 

      <select *ngSwitchCase="'LOVD'" class="form-control custom-select" type="text" [(ngModel)]="filterItem.value1" [ngModelOptions]="{standalone: true}" (change)="changeFilterValue(filterItem)"> 
       <option value="" ></option> 
       <option [hidden]="filterItem.defaultvalue1!=selectedLabel" *ngFor="let value of filterItem.values" [(value)]="value.code" required>{{value.displayName}}</option> 
      </select> 
     </span></div></div> 

現在,我有方法:如何判斷將填充哪個下拉列表?

changeFilterValue(value: any) { 
    this.selectedLabel = value.fieldlabel; 
    console.log('selected label',this.selectedLabel); 
    //this.selectFilterEmit.emit(this.selectedFilter); 
    } 

但我不知道我改一下下拉。任何建議如何檢測?

回答

1

你可以在下拉菜單中通過方法調用

(change)="changeFilterValue(filterItem, dropdownId)" 

和交換機基於在你的方法

changeFilterValue(value: any, dropdownId: int) { 
    switch(dropdownId) { 
    case 0: 
     // do for dropdown with ID 0 
     break; 
    default: 
     // do for default 
     break; 
    } 
} 

如果你只是想爲發出下拉列表中,你不需要切換你可以傳遞ID(或任何你想傳入的識別參數)到需要它的代碼部分。

+0

那是固定的數據,如果我在數據庫中添加更多的記錄我需要改變前端和更多的情況 – None

+0

不知道更多關於應用程序,這是一個難以回答的問題,就像我在我的答案中說的,你沒有要使用開關,您可以將下拉標識符傳遞給其他要處理的內容,或將其用作對象/ API調用的一部分中的字段 - 您需要提供更多詳細信息以瞭解如何處理此問題。 – 0mpurdy

+0

使用ngFor在數據庫和im中設置顯示所有下拉菜單。其中一些取決於其他。所以我想告訴一些取決於其他的下拉菜單,並在選擇第一個時填充它。它現在更清楚了嗎?所以他們都使用相同的ngFor,但顯示不同的數據,這就是爲什麼我需要知道什麼取決於什麼,並填充它。 – None

0

我建議你有兩個不同的下拉菜單的兩個不同的功能。