【发布时间】:2018-06-08 23:21:52
【问题描述】:
用户使用 dnd 插件在 jsTree 中移动节点后,我需要执行 ajax 调用。如果该 ajax 调用返回错误,我需要阻止移动发生,或者完全反转操作。从move_node 事件侦听器中,有没有办法告诉 dnd 插件反转丢弃或以某种方式取消操作?我尝试返回 false 并设置 e.preventDefault() 和 e.stopImmediatePropagation() 但似乎没有任何效果。
$($tree).jstree({
core: {
data: $treeData,
check_callback: function (op, node, parent, position, more) {
switch (op) {
case 'move_node':
// moveNode() validates the move based on
// some data stored in each node, but doesn't
// (and shouldn't) make an ajax call to determine
// if the node *actually can* be moved
return moveNode(node, parent, position, more);
}
}
},
plugins: ['dnd']
}).on('move_node.jstree', function(e, data) {
// moveNode() returned true and the user moved the node
if (!doMoveNode(data)) {
// none of this works!!
e.preventDefault();
e.stopImmediatePropagation();
return false;
}
});
【问题讨论】:
标签: jstree jstree-dnd