jsTree - 禁用拖动选项
如何禁用 jsTree 中的可拖动选项?我想禁用移动节点。我怎样才能实现这个目标?
how can I disable draggable option in jsTree? I want to disable moving nodes. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
它很简单。不要在插件中添加 dnd 选项
这包括拖动和拖拽。放置功能
这将禁用拖放功能。删除功能
"plugins": ["themes","html_data","ui","types"]
Its Simple.Do not add dnd option in plugins
This includes drag & drop functionality
This disables drag & drop functionality
"plugins": ["themes","html_data","ui","types"]
不将“dnd”添加到类型中确实有效。
您还可以使用插件上的属性,这将禁用所有移动。
Not adding the 'dnd' to the types does work.
You can also use the property on the pluggin, this will disable all moving.
只需添加以下内容:
它应该位于 types: 部分中。
simply add this:
it should be in the types: section.
这在新版本的 JSTree 中发生了变化。
我的做法(在 v1.0 中)是在 crrm 部分。我的 check_move 看起来像这样:
modata("rel") 是获取被拖动节点的类型的方式。
这使得该类型的节点无法被拖动,无论该节点被拖动到哪里,都会给它一个 X 图标。
This has changed in the newer version of JSTree.
The way I did it (in v1.0) was in the crrm section. My check_move looked like this:
m.o.data("rel") is how you get the type of the node being dragged.
This makes the node of that type not able to be dragged, giving it an X icon no matter where the node is dragged.
我想禁用拖放功能删除禁用的节点,这有效:
I wanted to disable drag & drop for disabled nodes, this worked:
is_draggable 属性似乎只能禁用将节点拖动到树内的其他位置。但节点仍然可以在页面上拖动。
因此,可以将节点拖到页面上的输入字段。
由于研究如何完全禁用拖动花了我一段时间,这对于偶然发现这个主题的其他人可能很有用。
您可以通过在事件上调用 PreventDefault() 来完全禁用拖动:
https://github.com/瓦卡塔/jstree/issues/1103
The property is_draggable seems to only disable dragging the Nodes to other positions inside the Tree. But the Nodes still remain draggable on the Page.
So it's possible for example to drag the Node to an input field on the Page.
Since researching how to completely disable the dragging took me a while, this might be usefull for others that stumble upon this topic.
You can completely disable dragging by calling preventDefault() on the Event:
https://github.com/vakata/jstree/issues/1103