Angular 如何实现;选择全部";及;取消全选“;ng2选择中的功能
我正在尝试使用ng2 select实现multiselect 这里是may view块代码Angular 如何实现;选择全部";及;取消全选“;ng2选择中的功能,angular,multi-select,selectall,Angular,Multi Select,Selectall,我正在尝试使用ng2 select实现multiselect 这里是may view块代码 <ng-select [multiple]="true" [items]="items" [disabled]="disabled" (data)="refreshValue($event)" (selected)="selected($event)"
<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;
}
private-value:any=[{id:“1”,text:“User A”}];
私有项:数组=[{id:“1”,文本:“用户A”},{id:“2”,文本:“用户B”},{id:“3”,文本:“用户C”}];
已选择私有(值:任意){
console.log('所选值为:',值);
}
私有删除(值:任意){
log('删除的值为:',值);
}
私有刷新值(值:任意){
这个值=值;
}
如何在其中实现“全选”和“取消全选”功能,并且ng select不是视图中的填充选择项。传递到已删除和选定功能中的值为
EventEmitter
,因此,要在组件中手动调用此函数(已删除或已选择),您可以根据需要多次调用它。因此,要取消全部选择,我们需要循环遍历项目总数并调用removed()函数,同时相应地传递相应的参数。
我们对selectAll()函数重复相同的过程,但在本例中,我们将在循环中调用select()函数。下面是代码的分解。我没有测试过这个,但应该可以
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
}
}
unselectAll():void{
对于(让i:number=0;我不能发布重复问题的重复答案,即使这是较旧的帖子,因此如果您需要答案,请参阅