JQuery/HTML5:组织结构图,如何使用该插件正确删除节点
JQuery/HTML5 : Organisational Chart, how to delete a node properly with this pluggin?
我想做一个组织结构图,但是我有一些问题…我使用JorgChart插件(http://www.webresourcesdepot.com/jorgchart-a-plugin-for-creating-interactive-organization-charts-with-jquery/)
事情是这样的:
-
我成功地做了双击事件来改变节点的名称,并正确地插入这个插件。
-
我成功地做了一个个性化的上下文菜单来添加/删除节点。
-
当我删除一个节点(而不是一个叶子)时,没有问题,节点变成灰色并失去他的名字;但是当我想删除一个叶子时,"节点"消失了,但"黑线"保留了下来。
我不知道如何在同一时间让这些行消失…
delete函数是这样的:
/* line 346 */
function removeNode() {
/* The node is desactivated, we put it in grey. */
lastClicked.addClass("nodeDeleted");
var $tr = lastClicked.closest('tr');
if(!lastClicked.hasClass("expanded")) {
$tr.html(" ");
/* We do the difference between the fact that the node disappared*/
console.log("We removed for real the node: "+lastClicked.html().trim().substring(0,14));
} else {
/* And the fact that we just put the none in grey. */
console.log("We desactived the node: "+lastClicked.html().trim().substring(0,14));
}
/* We erase the name of the node. */
lastClicked.html("");
}
它已经在IE11, Chrome和Firefox上测试过了,但是在Safari上可能会有一些问题。
JSFiddle: http://jsfiddle.net/ndt02yjc/1/
现在的结果:http://jsfiddle.net/ndt02yjc/embedded/result/
提前谢谢你,干杯!
Valentin,
我首先查看了您使用的插件生成的结构,例如boss3:
<td colspan="2" class="node-container">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr class="node-cells">
<td colspan="4" class="node-cell">
<div style="cursor: pointer;" class="node expanded">Boss 3</div>
</td>
</tr>
<tr>
<td colspan="4">
<div class="line down"></div>
</td>
</tr>
<tr>
<td class="line left"></td>
<td class="line right top"></td>
<td class="line left top"></td>
<td class="line right"></td>
</tr>
<tr>
<td colspan="2" class="node-container">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr class="node-cells">
<td colspan="2" class="node-cell">
<div style="cursor: pointer;" class="node expanded">Richard</div>
</td>
</tr>
<tr>
<td colspan="2">
<div class="line down"></div>
</td>
</tr>
<tr>
<td class="line left"></td>
<td class="line right"></td>
</tr>
<tr>
<td colspan="2" class="node-container">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr class="node-cells">
<td colspan="2" class="node-cell">
<div class="node">Bizut</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="2" class="node-container">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr class="node-cells">
<td colspan="2" class="node-cell">
<div class="node">Nicolas</div>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
所以我只是看了removeNode
函数来处理不同的情况:
如果所选项目有兄弟姐妹(同级别的其他人),我们只需要从所选项目的行之前的表行中删除2行:一个
right top
和left top
(参见带有这种行的表行来理解)如果选定的项目没有兄弟姐妹,那么您可以使用这些行删除表行,但仍将保留表行(形状之间的线由2行组成,以便处理行的水平部分),在这行之前,这就是为什么我使用
containerUpperLineRow
参见下面的函数:
function removeNode() {
var parentContainer = lastClicked.closest('.node-container');
var containerLowerLinesRow = parentContainer.parent().prev('tr');
var containerUpperLineRow = containerLowerLinesRow.prev('tr');
/* If item is a leaf, remove it and the lines */
if (!lastClicked.hasClass("expanded")) {
// Handle the lines going to the deleted item
if (parentContainer.siblings().length > 0) {
// More than one remaining node at the same level: drop a "right top" and a "left top" line
containerLowerLinesRow.children('.line.left.top:first').remove();
containerLowerLinesRow.children('.line.right.top:first').remove();
// Remove the selected item (from the node container)
parentContainer.remove();
} else {
containerUpperLineRow.prev('tr').find('.expanded').removeClass('expanded');
containerLowerLinesRow.remove();
containerUpperLineRow.remove();
// Remove the selected item (from the node container)
parentContainer.remove();
console.log("The node that we want to delete has no siblings");
}
console.log("We removed for real the node: " + lastClicked.html().trim().substring(0, 14));
} else {
/* If item is not a leaf, the node is desactivated, we put it in grey. */
console.log("We desactived the node: " + lastClicked.html().trim().substring(0, 14));
lastClicked.addClass("nodeDeleted").html(""); // And we erase the name of the node.
}
}
这里是提琴更新:http://jsfiddle.net/ndt02yjc/5/
最后一次编辑处理一个项的删除,该项在第一次删除时不是叶子项,但在进一步尝试时是叶子项
- Cordova插件在使用Framework7时不起作用
- 如何在RT上添加插件和使用一些外部模块/文件
- 在 webpack 插件中使用加载器
- 如何在Firefox插件中使用来自外部URI的contentScriptFile
- 将wirejs与jQuery插件结合使用
- 将RequireJs与自定义JS插件一起使用
- 如何在jquery的SWF对象插件中使用元素类名
- 如何在tinyscroll插件中使用水平滚动功能
- 如何创建一个火狐插件来使用 SDK 自动填写表单
- Ionic/Cordova-是否有一个媒体/mediaPlayer插件可以使用轨迹栏功能
- 如何在ngCordova文件插件中使用readAsText时设置编码
- wordpress在插件中使用.js脚本
- 如何加载JSON数据以将其与select2插件一起使用
- 在 Firefox 插件中使用 Core NodeJs 模块
- OKZoom 插件无法使用 svg 过滤器处理图像
- 在 Eclipse 插件中使用 JavaScript
- Firefox 插件:如何使用插件生成器调试简单存储
- 在我的咕噜声插件中使用 ncp 时出现问题
- 如何在草图插件中使用setImage
- 不确定如何将gridster.serialize()与Gridster jQuery插件一起使用