2014-02-28 3 views
0

사용자가 파일 &을 파일에 놓지 않도록하는 쉬운 방법이 있습니까?Dynatree는 비 폴더에서 드롭을 사용하지 않음

dynatree에는 파일을 이전 위치와 동일한 위치로 이동하려고하는지 확인하는 작은 스크립트가 있습니다. 그런 다음 사용자에게이 지점을 놓을 수 없음을 나타내는 작은 빨간색 십자가를 표시합니다.

폴더 만 만들 수있는 동일한 방법을 사용하는 경우 해결 방법이 있습니까? 당신은 단순히 onDragStart 나에 false를 반환 할 수 있습니다

답변

0

(나는 과거에 jstree를 사용,이 ... 당신은이를 설정할 수 있지만, dynatree 내 현재 프로젝트에 몇 가지 장점이있다, 그래서 나는 dynatree로 전환 할) 이 제어 할 수 onDrop 콜백 :

$("#tree").dynatree({ 
    ... 
    dnd: { 
     preventVoidMoves: true, // Prevent dropping nodes 'before self', etc. 
     onDragStart: function(node) { 
     /** This function MUST be defined to enable dragging for the tree. 
     * Return false to cancel dragging of node. 
     */ 
     return true; 
     }, 
     onDragEnter: function(node, sourceNode) { 
     /** sourceNode may be null for non-dynatree droppables. 
     * Return false to disallow dropping on node. In this case 
     * onDragOver and onDragLeave are not called. 
     * Return 'over', 'before, or 'after' to force a hitMode. 
     * Return ['before', 'after'] to restrict available hitModes. 
     * Any other return value will calc the hitMode from the cursor position. 
     */ 
     // Prevent dropping a parent below another parent (only sort 
     // nodes under the same parent) 
     if(node.parent !== sourceNode.parent){ 
      return false; 
     } 
     // Don't allow dropping *over* a node (would create a child) 
     return ["before", "after"]; 
     }, 
     onDrop: function(node, sourceNode, hitMode, ui, draggable) { 
     /** This function MUST be defined to enable dropping of items on 
     * the tree. 
     */ 
     sourceNode.move(node, hitMode); 
     } 
    } 

이 예제의 소스 코드를 살펴보고 http://wwwendt.de/tech/dynatree/doc/sample-dnd.html