Angular UI Tree - Allow only drag & drop into second level (children nodes)

2.8k Views Asked by At

I am currently using Angular UI Tree.

My object:

     [
          {
            "id": 1,
            "title": "class1",
            "students": [
              {
                "id": 11,
                "title": "student1.1",
              },
              {
                "id": 12,
                "title": "student1.2"
              }
            ]
          },
          {
            "id": 2,
            "title": "class2",
            "students": []
          },
          {
            "id": 3,
            "title": "class3",
            "students": [
              {
                "id": 31,
                "title": "student3.1"
              }
            ]
          }
        ]

What I want to achieve is to allow students to drag & drop inside classes (The classes do not have to be draggable, and students do not have to be dropped into first level (classes) only to a second level (students)).

Is this possible to achieve with Angular UI Tree?

1

There are 1 best solutions below

0
On

I finally made It like this:

I check in the destination Scope that parent is still a uiTreeNode.

In controller:

$scope.treeOptions = {
    accept: function(sourceNodeScope, destNodesScope, destIndex) {

        if (destNodesScope.$parent.$type === "uiTreeNode"){
                return true;
        }else{
            return false;
        }

    }
  };

and in view:

<div ui-tree="treeOptions">