我想实现多选择使用NG2选这里是我的看法块码,
<ng-select
[multiple]="true"
[items]="items"
[disabled]="disabled"
(data)="refreshValue($event)"
(selected)="selected($event)"
(removed)="removed($event)"
placeholder="Select from list"></ng-select>
在组件我有一个项目清单,并选择值列表
private value:any = [{id: "1", text: "User A"}];
private items:Array<Object> = [{id: "1", text: "User A"},{id: "2", text: "User B"},{id: "3", text: "User C"}];
private selected(value:any) {
console.log('Selected value is: ', value);
}
private removed(value:any) {
console.log('Removed value is: ', value);
}
private refreshValue(value:any) {
this.value = value;
}
它如何能够做到“全选”和“全部不选”功能和NG-选择不考虑填充选择项。
传递到删除,并且选择的功能值的类型EventEmitter<SelectItem>
的,因此调用此函数(删除或选择),手动在你的组件,你可以调用它多次,你want.Therefore,要取消选择所有,我们需要遍历项的总数和呼叫除去()函数而相应地传递适当的参数。我们重复同样的程序全选()函数,但在这种情况下,我们将调用循环instead.Below select()函数是code.I击穿没有测试,但这应该工作。
unselectAll():void {
for(let i:number=0;i<items.length;i++){
this.removed(items[i]);//we remove each SelectItem by invoking the removed function for each loop
}
}
selectAll():void {
for(let i:number=0;i<items.length;i++){
this.selected(items[i]); //we select the SelectItem by invoking the selected function for each loop
}
}