0

在此处输入图像描述

你好,我用的是nestable2,我想防止子节点拖到另一个父节点。它应该只被拖到它的父节点中。

我已经使用了 nestable2 的这种方法来获取源和目标。我想验证子节点不应拖到另一个父节点。它应该拖入其父级。我已经应用了以下方法,但它没有给我目的地类型,请建议帮助

  $('#nestable').nestable({
        beforeDragStop: function(l,e, p){
            // l is the main container
            // e is the element that was moved
            // p is the place where element was moved.
                var sourcetype = $(e).data('type');//field
                var destinationtype = $(p).data('type');//field
                var sourcegroupid = $(e).data('groupid');//5
                var destinationgroupid = $(p).data('groupid');//5
                if (sourcetype == 'field' && destinationtype == 'field') {

                    if (sourcegroupid == destinationgroupid)//suppose 5=5
                        return true;
                    else
                        return false;
                }
        }
    });
4

2 回答 2

0

只是想让您知道,将“数据类型”添加到 ol 元素是一个很好的逻辑,因为我自己的个性化可嵌套 2 是我所缺少的:D

这是我的代码,我曾经允许根中的孩子只能在主根内移动,而他们的所有孩子只能在“他们”之间移动。简而言之:第一层元素停留在第一层,第二层元素停留在第二层。

    beforeDragStop: function(l,e, p){
    var type = $(e).data('type');
    var type2 = $(p).data('type');

    if(type == 'root')
    {
        if(type2 != 'rooter')
            return false;
        else
            return true;
    }
    else if(type == 'child')
    {
        if(type2 == 'rooter')
            return false;
        else
            return true;
    }
}
于 2021-10-28T21:18:22.203 回答
0

在此处输入图像描述

在此处输入图像描述

通过在 ol 中分配类型也解决了这个问题。因为我试图将孩子拖到另一个 ol 列表,所以我必须给出相同的类型。

于 2020-06-29T11:37:51.243 回答