简体   繁体   English

从下拉可用选项中删除选定的选项

[英]remove selected option from drop-down available options

I have a drop-down and I need to remove the selected option and show the remaining options.我有一个下拉菜单,我需要删除所选选项并显示其余选项。 thanks in advance提前致谢

 FacultyorStudent_Data: Array<string> = ['Faculty/Coach','Student'] selected_FacultyorStudent: string = this.FacultyorStudent_Data[0]; SelectFacultyorStudent(FnS){ this.selected_FacultyorStudent=FnS; }
 <div class="text-center" id="perf-type" *ngIf="section=='practice'"> <h4 class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-bar-chart" aria-hidden="true"></i> &nbsp; <b>{{selected_FacultyorStudent}} &nbsp; <i class="fa fa-angle-down" style="font-size: 0.7em; font-weight: 700;"></i></b>&nbsp;&middot;<small>beta v4</small> </h4> <ul class="dropdown-menu" style="width: 20%; left: 40%;color: #337ab7;"> <li *ngFor="let item of FacultyorStudent_Data; let i = index;" class="text-center" [ngClass]="{'bg-selected-quiz': selected_FacultyorStudent==item}" (click)="SelectFacultyorStudent(item)"> {{item}}</li> </ul> </div>

In your FacultyorStudent_Data array iterate it through loop, and match if item is equals to the item you want to remove.在您的 FacultyorStudent_Data 数组中,通过循环对其进行迭代,如果项目等于您要删除的项目,则进行匹配。 If they match then remove it using splice method.如果它们匹配,则使用拼接方法将其删除。

In you.ts file:在 you.ts 文件中:

for(let i=0;i<this.FacultyorStudent_Data.length;i++){
   if(FacultyorStudent_Data[i]=='yourItemName'){
     this.FacultyorStudent_Data.splice(i,1)
   }
}

 if (FnS == 'Student'){ this.FacultyorStudent_Data.splice(0,1,'Faculty | Coach Insights') } else{ this.FacultyorStudent_Data.splice(0,1,'Student') } }

暂无
暂无

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

相关问题 如何从下拉列表中删除先前选择的选项但在编辑模式下显示? - How to remove the previously selected option from a drop-down but show in edit mode? 从 Angular 的下拉列表中删除选定的选项 - Remove selected option from drop down in Angular jQuery 使用 Javascript Object Literal 基于另一个下拉选项填充下拉选项 - jQuery populate drop-down options based on another drop-down option using Javascript Object Literal 根据在另一个下拉菜单中选择的内容在一个下拉菜单中显示选项 - Display options in a drop-down based on what is selected in another drop-down 根据另一个选定的下拉列表更改下拉列表中的选项 - Change options in a drop-down list depending on another selected drop-down list 如何使用取决于另一个下拉列表中所选选项的下拉列表显示表格简码 - how to display table shortcode with a drop-down list that depends on the selected option in another drop-down list 根据另一个下拉列表中的所选选项更改下拉列表中的项目 - Change items in a drop-down list depending on the selected option in another drop-down list 下拉框取决于在另一个下拉框中选择的选项 - Drop-down box dependent on the option selected in another drop-down box 仅当从不同的下拉菜单中选择了多个选项时,如何触发按钮出现 - How to trigger a button to appear only if multiple options from different drop-down menus have been selected Limit Checkboxes from getting checked when two separate drop-down options are selected? - Limit Checkboxes from getting checked when two separate drop-down options are selected?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM