在jsTree中获取检查的节点 [英] Get checked nodes in a jsTree

查看:110
本文介绍了在jsTree中获取检查的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于JSON数据的可运行的JSTree,并且复选框插件在每个项目旁边显示了一个框-到目前为止很好.现在,我想获取用户检查过的节点,以便可以对数据进行处理.

I have a working JSTree based on JSON data, and the checkbox plugin displays boxes next to each item -- so far so good. Now I want to get which nodes the user has checked, so I can do something with the data.

不幸的是,我还没有找到通过文档或网络搜索来做到这一点的方法.关于SO的一些回答是说要使用get_checked方法,但是我确实丢失了某些东西,或者我的JSTree版本没有该内容(即,该字符串没有出现在项目文件中的任何位置).我使用的是3.0.0版,这是目前最新的版本.

Unfortunately I haven't found a way to do it through the documentation or web searches. A few answers on SO say to use a get_checked method, but either I'm really missing something or my version of JSTree doesn't have that (i.e. that string doesn't appear anywhere in the project files). I'm on version 3.0.0, which is the latest right now.

有人可以向我指出a)如何获取选中的项目,或b)如何访问树的某些可迭代表示形式,以便我自己抓住它们吗?

Could someone please point me either to a) how to get the checked items, or b) how to access some iterable representation of the tree so I can grab them myself?

(我应该说我是Java的新手.)

(I should mention I'm pretty new to Javascript.)

这是我根据网站上的文档设置树的方式:

Here is how I set up the tree, which is based on the documentation on the website:

var treeInit = { core: { data : [
       /* all my data */
    ] 
}};
treeInit.plugins = ["checkbox"];
$('tree_div').jstree(treeInit);

推荐答案

我找到了答案.通过调用$('#tree').jstree('get_json'),您可以获取整个树的JSON表示形式.从那里开始,直接遍历树节点并获取所有选中的节点是非常简单的.同样,这是针对3.0.0版本的(因为该API在各个版本之间似乎已经发生了很大变化).

I found an answer. By calling $('#tree').jstree('get_json'), you can get a JSON representation of the whole tree. From there it's pretty straight forward to recurse through the tree nodes and grab all the checked ones. Again, this is for version 3.0.0 (since it seems that the API has changed a lot across versions).

这篇关于在jsTree中获取检查的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆