我使用SortableJS的角绑定是为了有一系列的拖放列表。当每个列表包含在自己的组件中时,拖放是否可能工作?
在视觉层面上,我能够重新排序列表中的项目。但是,在列表之间传输的项目在第二个项目被转移之前不会出现(请注意屏幕截图上部的“列表2”是如何丢失列表项"2“的,这是从”列表1“转移到”列表2“的最后一项)。
另一个问题是,通过拖放所做的任何更改都没有反映在列表的内容中--注意“查看结果”部分中的列表是如何与上面部分中的表示不匹配的。

我目前有如下代码:
父组件:
import { Component, OnInit } from '@angular/core';
import { ItemsService } from '../items.service';
@Component({
selector: 'app-multi-list',
template: `
<h2>Drag / drop the item</h2>
<h3>list 1</h3>
<app-list [(items)]="itemsService.items1"></app-list>
<h3>list 2</h3>
<app-list [(items)]="itemsService.items2"></app-list>
<hr>
<h2>See the result</h2>
<div>
<h3>list 1</h3>
<div *ngFor="let item of itemsService.items1">{{ item }}</div>
<h3>list 2</h3>
<div *ngFor="let item of itemsService.items2">{{ item }}</div>
</div>
`,
styleUrls: ['./multi-list.component.css']
})
export class MultiListComponent implements OnInit {
constructor(public itemsService: ItemsService) { }
ngOnInit() { }
}包含可排序列表的子组件:
import { Component, Input, OnInit } from '@angular/core';
import { SortablejsOptions } from 'angular-sortablejs';
@Component({
selector: 'app-list',
template: `
<div [sortablejs]="items" [sortablejsOptions]="{ group: 'test' }">
<div *ngFor="let item of items">{{ item }}</div>
</div>
`,
styleUrls: ['./list.component.css']
})
export class ListComponent implements OnInit {
@Input() items: any[];
ngOnInit() { }
}发布于 2017-12-11 15:36:02
对在不同组件中包含的列表之间传输内容的支持是添加到2.4.0版。
https://stackoverflow.com/questions/47741247
复制相似问题