【问题标题】:Dragable grid angular可拖动网格角度
【发布时间】:2020-07-26 18:51:27
【问题描述】:

我创建了一个网格,可以使用 angular cdkdrag 这样的代码重新排序

       <div class="col-lg-12" style="display: flex;flex-direction: row;flex-wrap: wrap;">
            <div class="row show-grid" cdkDropList (cdkDropListDropped)="drop($event)">
                <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 stepList" *ngFor="let steps of list" cdkDrag>
                    <nb-card class="projectListItem" routerLink="/project/steps-detail">
                        <nb-card-header>
                            <nb-icon class="projectIcon" icon="behance-outline"></nb-icon>
                            <h6 style="margin-top: 10px;">{{steps.title}} {{steps.id}}</h6>
                        </nb-card-header>
                        <nb-card-body>
                            {{steps.desc}}
                        </nb-card-body>
                    </nb-card>
                </div>
            </div>
        </div>

和这样的drop函数

      drop(event: CdkDragDrop<string[]>) {
        moveItemInArray(this.list, event.previousIndex, event.currentIndex);
      }

它不像我想要的那样工作,当我将 1 号移动到 4 号时,它应该使 1 号在 4 号位置,4 号滑到 3 号,3 号滑到 2 号,2 号滑到数字1.但它不那样工作,如果它是一个像表格一样的列表它应该工作,但它是一个我不知道会发生什么的网格,我错过了什么吗?

https://stackblitz.com/edit/angular-38vdnx?file=src%2Fapp%2Fapp.component.html

【问题讨论】:

    标签: angular angular-dragdrop angulardraganddroplists


    【解决方案1】:

    尝试改变html如下:

    <div class="col-lg-12" style="display: flex;flex-direction: row;flex-wrap: wrap;">
      <div class="row show-grid">
        <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 stepList" *ngFor="let steps of list" cdkDropList (cdkDropListDropped)="drop($event)">
          <nb-card class="projectListItem" routerLink="/project/steps-detail" cdkDrag>
            <nb-card-header>
              <nb-icon class="projectIcon" icon="behance-outline"></nb-icon>
              <h6 style="margin-top: 10px;">{{steps.title}} {{steps.id}}</h6>
            </nb-card-header>
            <nb-card-body>
              {{steps.desc}}
            </nb-card-body>
          </nb-card>
        </div>
      </div>
    </div>

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2016-02-02
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    相关资源
    最近更新 更多