如何使用分组创建Angular 2多选下拉列表?

时间:2018-01-16 07:45:10

标签: drop-down-menu angular2-directives multi-select

您好我正在开发AngularJS 2.我是AngularJS 2的新手。我正在尝试使用复选框创建多选下拉列表。我已经下载了npm install angular2-multiselect-dropdown。多选下拉列表工作正常。下面是我的html模板。

<angular2-multiselect [data]="dropdownListScopes" [(ngModel)]="selectedItemsScopes"
                                                  [settings]="dropdownSettingsScopes"
                                                  (onSelect)="onItemSelect($event)"
                                                  (onDeSelect)="OnItemDeSelect($event)"
                                                  (onSelectAll)="onSelectAll($event)"
                                                  (onDeSelectAll)="onDeSelectAll($event)">
</angular2-multiselect>
</div>
</div>  

我想编辑此下拉列表,使所有选项都有主菜单。我想实现分组功能。在文档中,我没有看到任何分组方法。有人可以帮我实现吗?谢谢。

1 个答案:

答案 0 :(得分:0)

https://www.telerik.com/kendo-angular-ui/components/dropdowns/multiselect/grouping/ 应该会帮助

import { GroupResult, groupBy } from '@progress/kendo-data-query';

@Component({
  selector: 'my-app',
  template: `
    <div class="example-wrapper">
        <kendo-multiselect
            [data]="groupedData"
            [textField]="'name'"
            [valueField]="'name'">
        </kendo-multiselect>
    </div>
  `
})
class AppComponent {
    public data: Array<any> = [
        { name: "Pork", category: "Food", subcategory: "Meat" },
        { name: "Pepper", category: "Food", subcategory: "Vegetables" },
        { name: "Beef", category: "Food", subcategory: "Meat" }
    ];
    public groupedData: GroupResult[] = groupBy(this.data, [{field: "subcategory"}]);
}