Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试向我们提供 Angular Material cdkDragDrop。
该列表正在尝试从嵌套对象中填充。我可以显示列表,但在尝试移动项目时,它不会出现在“添加的详细信息”列表中
代码:https ://stackblitz.com/edit/angular-awxclk?file=src%2Fapp%2Fcdk-drag-drop-connected-sorting-example.html
在您的代码中,您正在使用moveItemInArray并且transferArrayItem期望(顾名思义)第一个参数是一个数组。在您的情况下,您将其指向一个对象,因此该方法在内部抛出。
moveItemInArray
transferArrayItem
您想要做的是[cdkDropListData]在两个容器中使用实际的集合。*ngFor然后,您在指令中迭代那些相同的集合。
[cdkDropListData]
*ngFor
因此,在您的constructor/中,onInit您将对象转换为数组并将该数组用作[cdkDropListData]. 然后,如果您愿意,可以将数组转换回对象并在 drop 方法结束时对其进行更新。
constructor
onInit