嘿,我陷入了严重的卡住,无法用primeng从p-tree拖到p-panel中。
我尝试了很多方法,但是没有任何效果。
请有人可以帮助我吗? :(
<p-tree [value]="files" class="ui-helper-clearfix"
pDraggable="cars"
(onDragStart)="dragStart($event,file)"
(onDragEnd)="dragEnd($event)"
[(selection)]="selectedNode"
selectionMode="single"
draggableNodes="true"
droppableNodes="true"
(onNodeDrop)="onNodeDrop($event)"
(onNodeSelect)="onNodeSelect($event)"
></p-tree>
<div pDroppable="pnl" dragHandle=".ui-panel-titlebar"> <p-panel pDroppable="files" (onDrop)="drop($event)">
<div>
{{selectedTable}}
</div>
</p-panel>
</div>
public dragStart(event,table: TreeNode) {
this.draggedTable = table;
}
public drop(event) {
if(this.draggedTable) {
let draggedTableIndex = this.findIndex(this.draggedTable);
this.selectedTable = [...this.selectedTable, this.draggedTable];
this.files = this.files.filter((val,i) => i!=draggedTableIndex);
this.draggedTable = null;
}
}
public dragEnd(event) {
this.draggedTable = null;
}
public findIndex(node: TreeNode) {
let index = -1;
for(let i = 0; i < this.files.length; i++) {
if(node.label === this.files[i]) {
index = i;
break;
}
}
return index;
}