如何使用Primeng Tree使树节点可拖放到同一级别?

时间:2019-04-10 18:35:31

标签: json angular typescript primeng

当前行为:节点可以降到任何级别(我可以将父节点作为子节点和孙子节点,我可以使Child节点作为父节点和孙子节点,使孙子节点作为父子节点) 预期的行为:树应该只允许我们将节点放到同一级别 即,父节点应始终是父节点,子节点应始终是子节点,大子节点应始终是大子节点。

 Data=
  [
      {
          "label": "Documents",
          "data": "Documents Folder",
          "expandedIcon": "fa fa-folder-open",
          "collapsedIcon": "fa fa-folder",
          "children": [{
                  "label": "Work",
                  "data": "Work Folder",
                  "expandedIcon": "fa fa-folder-open",
                  "collapsedIcon": "fa fa-folder",
                  "children": [{"label": "Expenses.doc", "icon": "fa fa-file-word-o", "data": "Expenses Document"}, {"label": "Resume.doc", "icon": "fa fa-file-word-o", "data": "Resume Document"}]
              },
              {
                  "label": "Home",
                  "data": "Home Folder",
                  "expandedIcon": "fa fa-folder-open",
                  "collapsedIcon": "fa fa-folder",
                  "children": [{"label": "Invoices.txt", "icon": "fa fa-file-word-o", "data": "Invoices for this month"}]
              }]
      },
      {
          "label": "Pictures",
          "data": "Pictures Folder",
          "expandedIcon": "fa fa-folder-open",
          "collapsedIcon": "fa fa-folder",
          "children": [
              {"label": "barcelona.jpg", "icon": "fa fa-file-image-o", "data": "Barcelona Photo"},
              {"label": "logo.jpg", "icon": "fa fa-file-image-o", "data": "PrimeFaces Logo"},
              {"label": "primeui.png", "icon": "fa fa-file-image-o", "data": "PrimeUI Logo"}]
      },
      {
          "label": "Movies",
          "data": "Movies Folder",
          "expandedIcon": "fa fa-folder-open",
          "collapsedIcon": "fa fa-folder",
          "children": [{
                  "label": "Al Pacino",
                  "data": "Pacino Movies",
                  "children": [{"label": "Scarface", "icon": "fa fa-file-video-o", "data": "Scarface Movie"}, {"label": "Serpico", "icon": "fa fa-file-video-o", "data": "Serpico Movie"}]
              },
              {
                  "label": "Robert De Niro",
                  "data": "De Niro Movies",
                  "children": [{"label": "Goodfellas", "icon": "fa fa-file-video-o", "data": "Goodfellas Movie"}, {"label": "Untouchables", "icon": "fa fa-file-video-o", "data": "Untouchables Movie"}]
              }]
      }
  ];
  
  
 <p-tree [value]="Data" draggableNodes="true" droppableNodes="true"> </p-tree>

0 个答案:

没有答案