要使用Angular ng-multiselect-dropdown获取id,可以按照以下步骤操作:
npm install ng-multiselect-dropdown --save
import { Component } from '@angular/core';
import { IDropdownSettings } from 'ng-multiselect-dropdown';
export class AppComponent {
dropdownList = [];
selectedItems = [];
dropdownSettings: IDropdownSettings;
constructor() {
this.dropdownList = [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
{ id: 3, name: 'Item 3' },
// 添加更多选项...
];
this.dropdownSettings = {
singleSelection: false,
idField: 'id',
textField: 'name',
selectAllText: 'Select All',
unSelectAllText: 'Unselect All',
itemsShowLimit: 3,
allowSearchFilter: true
};
}
}
onItemSelect(item: any) {
console.log(item);
// 获取选中项的id
console.log(item.id);
}
onSelectAll(items: any) {
console.log(items);
// 获取所有选中项的id
let selectedIds = items.map(item => item.id);
console.log(selectedIds);
}
通过上述步骤,您就可以使用ng-multiselect-dropdown获取选中项的id了。