angular - 如何设计树形多选下拉菜单
问题描述
我需要以角度设计树样式下拉菜单。示例图像附在此处。当用户勾选列表项时,项目打印在标签上。
我需要像图片中一样添加子类别:N1、N1.1、N1.2。怎么做?
这是我现有的代码。我使用 Angular 多下拉菜单进行选择。我需要将此代码修改为树视图。在下拉列表中,第一项“北脊椎”具有子类别“N1”、“N1.1”、“N1.2”和“N1.3”。因此,与现有项目相同,当用户勾选时需要在标签上打印(请参阅附图)。当用户勾选每个项目将显示在标签上并可以从中删除。
<div class="col-sm-6 form-group">
<label for="Building">Authorized Building</label>
<ng-multiselect-dropdown
[placeholder]="'Select the Building'"
[settings]="dropdownSettings"
[data]="dropdownList"
[(ngModel)]="selectedItems"
(onSelect)="onItemSelect($event)"
(onSelectAll)="onSelectAll($event)">
</ng-multiselect-dropdown>
</div>
导出类 UserComponent 实现 OnInit {
dropdownList: { item_id: number; item_text: string; }[] = [];
selectedItems: { item_id: number; item_text: string; }[] = [];
dropdownSettings : IDropdownSettings;
constructor(public service: UserService) { }
ngOnInit(): void {
//dropdown list value
this.dropdownList = [
{ item_id: 1, item_text:'North Spine'},
{ item_id: 2, item_text: 'Academics' },
{ item_id: 3, item_text: 'Staff Housing' },
{ item_id: 4, item_text: 'Student Hall' },
];
this.selectedItems = [
{ item_id: 3, item_text: 'North Spine' },
{ item_id: 4, item_text: 'Academics' }
];
this.dropdownSettings = {
singleSelection: false,
idField: 'item_id',
textField: 'item_text',
selectAllText: 'Select All',
unSelectAllText: 'UnSelect All',
itemsShowLimit: 4,
allowSearchFilter: true
};
}
//dropdownlist
onItemSelect(item: any) {
console.log(item);
}
onSelectAll(items: any) {
console.log(items);
}
}
解决方案
推荐阅读
- javascript - 当我在选择标签中选择一个选项时如何打开一个新标签?
- javascript - 如何在 hbs 文件中使用外部文件中的 javascript 方法
- spring-batch - Spring Batch - 我们可以在循环中使用日期列从数据库中读取项目吗
- angular - Mat-error 无法与 mat-select 一起正常工作
- laravel - 无法在 Laravel 中更新数组数据
- amazon-quicksight - 是否可以检索由 AWS QuickSight 生成的预测?
- python - Python - Matplotlib:从单轴上的多个 pcolormesh 收集数据
- javascript - 如何解决分页问题?
- django - 使用来自 cookie 的 Django 会话 ID 来验证 Vue 应用程序
- c++ - 向 CPLEX 添加约束不起作用 C++ API