Javascript JSTree-DND不接受退货
我被困住了,希望有人能帮我解决这个问题。我用三种节点类型填充JStreeJavascript JSTree-DND不接受退货,javascript,jquery,jstree,Javascript,Jquery,Jstree,我被困住了,希望有人能帮我解决这个问题。我用三种节点类型填充JStree 文件夹 计划 工作 在尝试将一个节点拖放到另一个节点时,需要考虑一些规则 文件夹可以有“文件夹”和“项目”类型的子文件夹 项目只能有“job”类型的子项 乔布斯不能有孩子 问题:JSTree忽略我返回的布尔值,并允许对所有元素使用DND。正常情况下,返回“false”将设置红色X,并且不允许下降,但情况并非如此。我已经将函数checknodeecb()返回到控制台,我的真/假逻辑似乎是正确的。请参见下面的我的代码:
- 文件夹
- 计划
- 工作
- 文件夹可以有“文件夹”和“项目”类型的子文件夹
- 项目只能有“job”类型的子项
- 乔布斯不能有孩子
core: {
check_callback: function(e,node,parent,position,more){
function checkNodeCB(oNode,tNode){
if(tNode.type === "folder" && oNode.type !== "job"){
//console.log("I want to place a "+oNode.type+" inside a folder");
return true;
}
if(tNode.type === "project" && oNode.type === "job"){
//console.log("I want to place a job under a project");
return true;
}
return false;
};
if((e === 'copy_node' || e === 'move_node') && more.dnd){
if (oldNode !== more.ref.id){
oldNode = more.ref.id; //Set the oldNode to the current ID so it no longer executes
//console.log(checkNodeCB(node.original,more.ref.original));
return checkNodeCB(node.original,more.ref.original);
}
}
return true;
},
worker: true
},
dnd:{
check_while_dragging:true
},
就像每一个开悟的时刻一样,我走开去照顾大自然母亲,意识到我做错了什么。当我的鼠标移动到另一个节点上时,我试图通过只执行checknodebc()函数来提高代码的效率,但忽略了在函数外部返回值仍被设置为true。代码并不完美,但这就是我最终得到的
check_callback: function(e,node,parent,position,more){
function checkNodeCB(oNode,tNode){
if(tNode.type === "folder" && oNode.type !== "job"){
outPut = true;
}
if(tNode.type === "project" && oNode.type === "job"){
outPut = true;
}else{
outPut = false;
}
};
if((e === 'copy_node' || e === 'move_node') && more.dnd){
if (oldNode !== more.ref.id){
oldNode = more.ref.id; //Set the oldNode to the current ID so it no longer executes
checkNodeCB(node.original,more.ref.original);
}
return outPut; //Use the output variable so the state persists when moving the mouse over the current "hovered" node
}
return true;
},