是否有一种简单的方法可以避免用户丢弃文件&文件夹到文件?
dynatree中有一个小脚本可以检查你是否尝试将文件移动到同一位置。然后它会显示一个小红叉,向用户显示此点不可丢弃。
是否有解决方法使用相同的方法只使文件夹可丢弃? (我过去使用过jstree,你可以设置它,但是dynatree对我当前的项目有一些优势,所以我想切换到dynatree ......)
答案 0 :(得分:0)
您只需在false
或onDragStart
回调中返回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