【问题标题】:Nestable2- How to prevent child node to dragged in another parent node?Nestable2-如何防止子节点拖入另一个父节点?
【发布时间】:2020-06-29 10:40:28
【问题描述】:

你好, 我使用了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;
                }
        }
    });

【问题讨论】:

    标签: drag-and-drop draggable jquery-nestable


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      只是想让您知道,将“数据类型”添加到 ol 元素是我自己的个性化可嵌套对象缺少的一个很好的逻辑: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;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-07
        • 1970-01-01
        • 2014-11-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多