简体   繁体   English

Angular Material拖放CDK删除列表中的元素

[英]Angular Material drag n drop CDK remove element on list

How can I remove a list item?如何删除列表项? I tried removing the item from the array associated with the list, but this breaks the list altogether.我尝试从与列表关联的数组中删除该项目,但这完全破坏了列表。

I use Angular (with Material) 9.0我使用 Angular(带材质)9.0

I have 2 lists.我有 2 个列表。 When I drag an item from the first list (sequenceOfSlides) to the second (listOfSlides), I delete it, and from the second to the first I copy it.当我将一个项目从第一个列表 (sequenceOfSlides) 拖到第二个 (listOfSlides) 时,我将其删除,然后从第二个列表到第一个列表复制它。 The problem was that I removed the elements from the array associated with the list with its full replacement.问题是我从与列表关联的数组中删除了元素,并完全替换了它。 With @Eliseo, I began to remove elements from the original array without changing the link to it.使用@Eliseo,我开始从原始数组中删除元素而不更改指向它的链接。 Template:模板:

 <div class="row" cdkDropListGroup> <div class="col-6"> <div id="sequenceOfSlidesElement" cdkDropList [cdkDropListData]="sequenceOfSlides" class="example-list" (cdkDropListDropped)="drop($event)"> <div class="example-box" *ngFor="let item of sequenceOfSlides" cdkDrag> {{item.ruName}} </div> </div> </div> <div class="col-6"> <div id="listOfSlidesElement" cdkDropList [cdkDropListEnterPredicate]="noReturnPredicate" [cdkDropListData]="listOfSlides" class="example-list" (cdkDropListDropped)="drop($event)"> <div class="example-box" *ngFor="let item of listOfSlides" cdkDrag> {{item.ruName}} </div> </div> </div> </div>

Component:成分:

 drop(event: CdkDragDrop<ISlide[]>) { if (event.previousContainer === event.container) { moveItemInArray(event.container.data, event.previousIndex, event.currentIndex); } else { if (event.container.id === 'sequenceOfSlidesElement') { copyArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex); } else { this.sequenceOfSlides.splice(event.previousIndex, 1); } } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular Material拖放CDK - 将单个元素(独立)放入列表 - Angular Material drag drop CDK - drop single element(independent) into a list 使用Angular 7 Material CDK拖放 - drag and drop with Angular 7 Material CDK 拖放cdk Angular素材 - Drag and drop cdk Angular material Angular cdk 拖放到 Material 对话框 - Angular cdk drag and drop into Material dialog 使用 Angular 7 Material CDK 嵌套拖放 - Nested Drag and Drop in with Angular 7 Material CDK Angular 材质 CDK 拖放 对齐网格内部元素 cdkDragConstrainPosition @Input 用于拖放元素内的元素 position - Angular Material CDK Drag and Drop Snap To Grid Internal Element cdkDragConstrainPosition @Input for element inside the Drag and Drop element position 尝试清除Angular 8 CDK拖放列表 - Trying to clear Angular 8 CDK Drag and Drop List 在 Angular Material CDK Drag Drop 中,如何防止项目随着元素移动而自动重新排列? - In Angular Material CDK Drag Drop, How to Prevent Items from Automatically Rearranging as an Element Moves? 角度拖放cdk在角度材质对话框中不起作用 - angular drag and drop cdk doesn't work in angular material dialog 带有表格主体/行扭曲宽度的 Angular CDK 拖放列表(无材质) - Angular CDK Drag/Drop List with table-body / rows distorting width (without Material)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM