如何判断将填充哪个下拉列表?

问题描述:

<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); 
    } 

但我不知道我改一下下拉。任何建议如何检测?

你可以在下拉菜单中通过方法调用

(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

我建议你有两个不同的下拉菜单的两个不同的功能。