【问题标题】:JSTree - DND Not Honoring ReturnJSTree - DND 不尊重回报
【发布时间】:2015-04-13 20:46:19
【问题描述】:

我被困住了,我希望有人能帮我解决这个问题。我使用三种节点类型填充 JStree。

  • 文件夹
  • 项目
  • 工作

在尝试将一个节点拖放到另一个节点时,我需要考虑一些规则。

  • 文件夹可以有“文件夹”和“项目”类型的子文件夹
  • 项目只能有“工作”类型的子项
  • 工作不能有孩子

问题:JSTree 忽略了我返回的布尔值并允许对所有元素进行 DND。通常返回“false”会设置红色 X 并且也不允许放置,但事实并非如此。我已经将函数 checkNodeCB() 的返回写入控制台,并且我的真/假逻辑似乎是合理的。请参阅下面的代码:

  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
  },

【问题讨论】:

    标签: javascript jquery jstree


    【解决方案1】:

    就像每一个开悟的时刻一样,我离开去照顾大自然,并意识到自己做错了什么。当我的鼠标移到另一个节点上时,我试图通过只执行 checkNodeCB() 函数来提高我的代码效率,并且忽略了在函数之外仍然将返回设置为 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;
         },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多