首页 > 解决方案 > 如何基于 [sortablejs] 使按钮启用/禁用

问题描述

我有一个具有拖放功能的列表

<div   [sortablejs]="actionList"> 

<div *ngFor="let data of actionList | filterBy: searchValue;let i = index">

还有一个像下面这样的按钮

<button  (click)="save()">  Save</button>

如何仅在用户进行拖放时启用此按钮这里我使用SortablejsModule进行列表的拖放功能

标签: angulardrag-and-dropsortablejs

解决方案


您可以像这样将 drageableOption 作为参数,并在拖放事件发生时附加一个函数。

在你的html

<div   [sortablejs]="actionList" [sortablejsOptions]="draggableOptions"> 

<div *ngFor="let data of actionList | filterBy: searchValue;let i = index">

在你的.ts

从 'angular-sortablejs' 导入 { SortablejsOptions };

export class StockMovementComponent implements OnInit{

disableButton: boolean = true;

draggableOptions : SortablejsOptions = {
    animation: 150,
    onUpdate: () => this.dragDropDataSuccess(),
    scroll: true,
    scrollSensitivity: 100
  };

constructor(){}

ngOnInit() {}

dragDropDataSuccess(){
this.disableButton = false;
}

}

推荐阅读