- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 JSTree
,这是我对 contextmenu
插件的设置:
"contextmenu":{
"items": function($node) {
return {
"Remove": {
"separator_before": false,
"separator_after": false,
"label": "Delete group",
"action": function (obj) {
$tree.jstree("get_children_dom", $node).each(function(child){
$tree.jstree("move_node", $tree.jstree("get_node", child, true), "#", "last", function(node, parent, pos){
alert(1);
});
});
$tree.jstree("delete_node", $node);
}
}
};
}
}
基本上,我希望将要删除的组的子项向上移动。我目前得到的函数应该把节点放在最后,但是我怎样才能把它们放在删除节点的地方呢?此外,当前代码不起作用 - 我做错了什么?
最后但同样重要的是,我如何在删除之前检查节点类型?
提前致谢
最佳答案
basically, I want the children of the group that's being deleted to be moved upwards.
如果向上是指进入被删除节点的位置,请检查以下示例:
var data = [{
'text': 'item 1',
'children': [{
text: 'item 1-1',
children: [{
text: 'item 1-1-1',
children: [{
text: 'item 1-1-1-1'
}, {
text: 'item 1-1-1-2'
}]
}, {
text: 'item 1-1-2'
}, {
text: 'item 1-1-3'
}]
}, {
text: 'item 1-2',
children: [{
text: 'item 1-2-1'
}, {
text: 'item 1-2-2'
}]
}, {
text: 'item 1-3',
children: [{
text: 'item 1-3-1'
}, {
text: 'item 1-3-2'
}]
}, {
text: 'item 1-4',
children: [{
text: 'item 1-4-1'
}, {
text: 'item 1-4-2'
}]
}]
}, {
'text': 'item 2',
children: [{
text: 'item 2-1',
children: [{
text: 'item 2-1-1'
}, {
text: 'item 2-1-2'
}]
}, {
text: 'item 2-2',
children: [{
text: 'item 2-2-1'
}, {
text: 'item 2-2-1'
}]
}, {
text: 'item 2-3'
}]
}, {
'text': 'item 3',
children: [{
text: 'item 3-1',
children: [{
text: 'item 3-1-1'
}, {
text: 'item 3-1-2'
}]
}, {
text: 'item 3-2'
}]
}, {
'text': 'item 4 (you cannot delete this one)',
'disableDelete': true,
children: [{
text: 'item 4-1'
}, {
text: 'item 4-2'
}, {
text: 'item 4-3'
}]
}];
var $tree = $('#jstree_demo').jstree({
'plugins': ['contextmenu'],
'core': {
'animation': 0,
'check_callback': true,
'themes': {
'stripes': true
},
'data': data
},
'contextmenu': {
'items': function($node) {
return {
'Remove': {
'separator_before': false,
'separator_after': false,
'label': 'Delete group',
'action': function(obj) {
if ($node.original.disableDelete) {
document.write('deletion is forbidden for this node');
return;
}
var nodes = $node.children.slice(0); // jstree behaves erratic if we try to move using $node.children directly, so we will clone the array to prevent this issue
var $row = $(obj.reference[0].closest('li'));
$tree.jstree('move_node', nodes, $node.parent, $row.index());
$tree.jstree('delete_node', $node);
}
}
};
}
}
});
<div id="jstree_demo"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css">
Last but not least, how can I check the node type before removing?
我添加了一个小示例来向您展示如何完成它。检查自定义属性 disableDeletion
对节点的声明:
var data = [{'text': 'item 4 (you cannot delete this one)', 'disableDelete': true}]
以及上下文菜单操作中的验证:
if ($node.original.disableDelete) {
document.write('deletion is forbidden for this node');
return;
}
关于javascript - JSTree:移动所有子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33133610/
我试图在不重新加载或刷新页面的情况下重新加载 jstree,重新加载应该发生在按钮的 onclick 上,因此当单击按钮时我调用 $("#tree-container").jstree('destro
在我的页面上,我有一个按钮,单击该按钮会刷新该页面上找到的 jstree。 现在,当 jstree 加载时,将从 2D 数组中读取数据,并根据该数组中找到的数据更改节点图标。我需要一个函数来刷新或重
我正在尝试使用 jstree 并在打开页面时打开一个节点及其所有父节点。这是我用来测试的html代码。 TEST1
有没有人尝试过使用类型插件更改 jstree 特定节点的颜色?而且我还想避免该节点上的点击事件。 我需要这样做以防止用户选择相同的节点。 最佳答案 关于如何更改任何被点击节点的颜色的示例: $(fun
我将 jsTree 与复选框插件一起使用。我将级联设置为“向下”。这很好用,除了当我想加载包含已选中和未选中节点的数据时,级联会覆盖节点的“状态”设置。例如。 var data = [ {"i
为了在jsTree中存储任意数据节点,我将自定义属性(例如 node-data)传递给 create_node方法。但我需要在单个属性中存储多条数据。 (例如姓名、年龄等)哪种格式最适合节点数据属性的
有没有办法以编程方式关闭 jsTree 中的上下文菜单?我实现了一种使用 show_contextmenu 在悬停时打开上下文菜单的方法,但我需要在鼠标离开时关闭它 最佳答案 好的,通过查看代码我找到
当还选择了父节点时,我在选择子节点时遇到了困难,还想打开子文件夹并选择所有子节点(不确定我是否说清楚)所以我知道如何通过以下方式获取所有子节点: selected_nodes = $("#demo")
我需要显示一个 JSTree 但不能展开和折叠。有什么办法可以实现吗? 在下面的链接中提到禁用展开和折叠在 jstree 中不可用,这似乎是一个错误。 https://groups.google.co
如何在 jsTree 1.0 中禁用移动,但不禁用 dnd 插件? 谢谢。 最佳答案 我找到了解决方案。 $("#tree").jstree({ //... "crrm" : {
我的 jstree 配置如下: var $proceduresTree = $('#procedures-tree'); $proceduresTree.jstree({ 'core' : {
我使用插件 Jstree 绘制文件夹和文件树。 我想获取顶部的文件夹列表,然后获取文件列表(文件夹和文件列表必须按字母顺序排序)。 这是我的树初始化函数: $('#jstree_demo_div').
这是我处理这个问题的最后手段。 问题是我无法从下面的示例数据中获取具体值。 我很着急,如果您能回答这个问题,我将不胜感激。 这是我的代码。 $("#organize").jstree( {
在我的网站中,我有一个下拉选择选项,列出了 MySQL 中可用的数据库。在每个数据库中,我都有一个名为树的表。每当选择选项更改为新数据库或发生页面重新加载时,我都会将数据库名称发布到 php 文件中。
我正在使用 jstree 并且 select_node.jstree 不会触发,这是代码 $(document).ready(function () { //$("#MySplitter").spli
要将节点添加到我的树中,我使用 JavaScript 推送: var parent1 = { "id": "parent1", "data": {extra:"some extra d
如何获取jsTree中的所有节点? 我正在用 xml 构建 jsTree Root -----A -----A1 -----A1.1
如果我没记错的话,当使用 jstree 时,如果检查了父节点,那么它的子节点也会被检查。像这样 我正在做的是,我正在进行 ajax 调用并仅加载父节点。我检查了父节点,当我展开父节点时,我正在进行另一
是否可以为 jsTree jQuery plugin/library 生成的类名添加前缀?如果没有,是否有已知的路径可以让单个页面共享两个样式不同的 jsTree 元素? 问题: 我有一个(基于 PH
我的 jsTree 包含在树加载时设置的 html 数据(请参阅下面的 javascript)。这工作正常。但是,我希望能够根据某些用户操作在 Ajax 请求中重新加载整个树。我基本上需要重新加载从
我是一名优秀的程序员,十分优秀!