Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为增加兄弟节点函数增加指定增加到右边的参数选项 #748

Open
easythd opened this issue May 14, 2024 · 0 comments
Open

Comments

@easythd
Copy link

easythd commented May 14, 2024

因为默认的增加兄弟节点函数addSiblings固定把新节点增加到指定节点的左边,而在项目使用过程中,我需要用到指定增加到右边,找了一圈issues,发现也有人有类似需求但一直没有解决这个问题,所以通过跟踪尝试,调整了一下源码,给addSiblings函数加了个指定增加到右边的参数,调整了2个函数,addSiblings和buildSiblingNode,这两个函数在源代码里本身是就是紧挨在一起的,调整如下,有用的请参考。

` 修改的jquery.orgchart.js文件

// build the sibling nodes of specific node
buildSiblingNode: function ($nodeChart, data, isRight=false) {
  ..............原来的代码不变...................
  if ($nodeChart.closest('.nodes').parent().is('.hierarchy')) {
  ..............原来的代码不变..................
  } else { // build the sibling nodes and parent node for the specific ndoe
    if (isRight) { //如果传入了isRight参数并且为true,则将新兄弟节点插入到指定节点的后面,否则默认插入到前面
      this.buildHierarchy($nodeChart.parent().append($('<li class="hierarchy">')).children('.hierarchy:last'), data);
    } else {
      this.buildHierarchy($nodeChart.parent().prepend($('<li class="hierarchy">')).children('.hierarchy:first'), data);
    }
    $nodeChart.prevAll('.hierarchy').children('.nodes').children().eq(insertPostion).after($nodeChart);
  }
},
//
addSiblings: function ($node, data, isRight=false) {
  this.buildSiblingNode($node.closest('.hierarchy'), data, isRight);
  ..............原来的代码不变...................

`

@dabeng 因为不知道是否还有别的什么地方涉及这个需求,我也没改别的,改的上述这点已经够我的项目中需求用了。如果合适,希望可以加入下一发布版本。谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant