简体   繁体   English

Dragula 服务在目标中添加最后一滴

[英]Dragula service adding last drop in the target

I trying to fix an issue with an application built on angular 5.5 with dragula 1.5.0 .我试图解决一个基于 angular 5.5 和 dragula 1.5.0 的应用程序的问题。 the code is working fine if only one drag and drop performed.如果只执行一次拖放操作,代码就可以正常工作。 though on the user interface its showing the right thing.虽然在用户界面上它显示了正确的东西。 but I am not sure how to manipulate it.但我不知道如何操纵它。 here is the code.这是代码。

        this.dragulaService.drag.asObservable().pipe(takeUntil(this.destroy$)).subscribe((value) => {
        const dragValue = value[1].innerText;
        const dragValues = dragValue.trim().trim('\n').split('\t');
        this.dragValue = dragValues[1];
    });

this.dragulaService.drop.asObservable().pipe(takeUntil(this.destroy$)).subscribe((value) => {
        const values = value[2].innerText;
        const dropValues = values.trim().trim('\n').split('\t');
        if (this.dragValue === dropValues[1]) {
            this.dropBeforeValue = dropValues[12];
        } else {
            this.dropBeforeValue = dropValues[1];
        } }

now when I am accessing the element after first drop its working fine as the elements are in place as per first drop.现在,当我在第一次放下后访问元素时,它的工作正常,因为元素在第一次放下时就位。 but on the second drop it also contains previous or first drop value which make dropValues array size more.但在第二次删除时,它还包含前一个或第一个删除值,这使得 dropValues 数组大小更大。 is there any way that every drag and drop should only contain current values?有没有办法让每次拖放都只包含当前值?

Thanks in advance提前致谢

You can use dropModel to get all the information:您可以使用 dropModel 获取所有信息:

this.dragulaService.dropModel(this.bag)
            .subscribe(
                (value: {
                    name: string; el: Element; target: Element;
                    source: Element; sibling: Element; item: any; sourceModel: any[]; targetModel: any[]; sourceIndex: number; targetIndex: number;
                }) => {
                    ...handle it
                }));

Just don't forget to set the dragula model只是不要忘记设置dragula模型

<div [dragula]="bag"
     [(dragulaModel)]="someArray"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM