如何获取children属性ID's在jsTree中

How do i get children-attribute ID's in jsTree

本文关键字:jsTree ID 属性 何获取 获取 children      更新时间:2023-09-26

首先,我对javascript很陌生,并尝试让它工作数小时。

Q: 我使用的是带有复选框的jsTree(请参阅此链接:http://nuijten.blogspot.de/2013/07/apex-tree-with-checkboxes.html)我想填写一个数组,其中包含所有检查子项的ID(2级树,多个根,每个根有多个子项)

我能做的最好的事情就是把所有的ID都放到数组中,包括根的ID。

var lmetrics = [];
$("#metrics-tree a.checked, a.undetermined").parent()
.each(function() 
{
  lmetrics.push($(this).attr("id")); 
});

也在函数中尝试了类似的东西:

if ($this.children("a").hasClass("checked"))
    lmetrics.push($(this).attr("id"));

但我想我犯了一些重大错误

提前感谢,Thomas

你能试试这个吗

var inst = $.jstree.reference('#yourTreeDiv');
var checkedNodes = inst.get_checked();

贪婪,

Martin