javascript - jsTree加载并点击

标签 javascript jquery jstree

我有两个关于 jsTree 的问题:

  1. 我正在使用 JSON 和 struts2 生成一个 jsTree。第一次正确显示树。但是在单击按钮时,我想将具有不同数据的树重新加载到同一个 div 中。在单击按钮时,我给出了与第一次生成 jstree 时相同的操作名称。

  2. 如果我单击树的任何节点,那么我需要该节点的 ID,如果该节点有任何父节点,则还需要该节点的父节点 ID,父节点有父节点,然后是该节点的 ID父节点也是

例子

    Parent 1
       |__Parent 2
            |__Child 1

我正在点击 Child 1,然后我想要 Child 1、Parent 2、Parent 1 等的 ID。

最佳答案

我不确定你是否真的浏览过文档,但这里有一些可以帮助你的东西:

对于你的第一个问题,你可以使用回滚:http://luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/5_others.html 刷新也可以是一个选项:http://luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/2_operations.html

对于你的第二个问题,你可以使用回调:http://luban.danse.us/jazzclub/javascripts/jquery/jsTree/reference/_examples/3_callbacks.html

._get_parent 也会帮助你:

._get_parent ( node )

Gets the LI element representing the parent of the passed node. Returns false on failure. mixed node

This can be a DOM node, jQuery node or selector pointing to an element within the tree, whose parent we want.

有关详细信息,请参阅完整文档:http://www.jstree.com/documentation/core

关于javascript - jsTree加载并点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8120617/

相关文章:

JavaScript 无法读取 null 的属性 'parentElement'

javascript - 如何用jquery裁剪图像?

c# - 自动完成在带有母版页的 ASP.Net webform 中不起作用

javascript - 尝试获取 jstree 中 Change_state 上已检查项目的列表

javascript - 尝试设置 node.js Web 服务器

javascript - for-loop 无限循环由于变量冲突

javascript - 如何使用 JavaScript 和 Nth-Last-Child 添加和删除 CSS 类?

javascript - 如何在 Canvas 中将轴更改为左下角后修复鼠标事件

javascript - 这个 jsTree 元素上的 JQuery 脚本到底做了什么?

javascript - jsTree搜索文本框不出现