首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SortableJS角2.0+绑定:不同组件中两个列表之间的拖放

SortableJS角2.0+绑定:不同组件中两个列表之间的拖放
EN

Stack Overflow用户
提问于 2017-12-10 17:04:07
回答 1查看 721关注 0票数 0

我使用SortableJS的角绑定是为了有一系列的拖放列表。当每个列表包含在自己的组件中时,拖放是否可能工作?

在视觉层面上,我能够重新排序列表中的项目。但是,在列表之间传输的项目在第二个项目被转移之前不会出现(请注意屏幕截图上部的“列表2”是如何丢失列表项"2“的,这是从”列表1“转移到”列表2“的最后一项)。

另一个问题是,通过拖放所做的任何更改都没有反映在列表的内容中--注意“查看结果”部分中的列表是如何与上面部分中的表示不匹配的。

我目前有如下代码:

父组件:

代码语言:javascript
复制
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() { }

}

包含可排序列表的子组件:

代码语言:javascript
复制
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() { }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-11 15:36:02

对在不同组件中包含的列表之间传输内容的支持是添加到2.4.0版

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47741247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档