在jstree中选择父级时如何获取子级路径 [英] How to get path of children when parent is selected in jstree

查看:448
本文介绍了在jstree中选择父级时如何获取子级路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试选择父级时,我试图获取父级和子级节点的路径.为了获得所选节点的路径,我执行了以下操作:

 $("#jstree_demo_div").jstree({
    "core" : {
       "data" : {
          "type" : "POST",
          "url" : "myurl.php",
          "data" : function (node) {
                  return { "id" : node.id };
              }
       },
       "dataType" : "json",
    },
    "plugins" : [ "wholerow", "checkbox", "types" ]
 })
 .on("changed.jstree", function (e, data) {
    var path = $("#jstree_demo_div").jstree(true).get_path(data.node,"/");
    console.log ("path = " + path + "\n");
 });""

但是我不知道如何获得孩子父母的道路.

我试图获取孩子的父母的ID,然后应用split()函数以获取ID的孩子,然后应用get_path(),但这不起作用,因为它说split不是函数.

var test = data.node.children;
var spt_tst = test.split(',');
alert("node = " + spt_tst[0]);

我在做什么错了?

****编辑****

我的树就像图中所示:

我想做的是:选择文件夹图像并获取所有内容的路径,例如,我想获取内部内容的路径. xvpics 文件夹以及其他文件夹.因为我必须将这些路径发送到.txt文件.

解决方案

data.node.children返回一个数组,您可以通过索引对其进行访问.要获取第i个元素,请使用data.node.children[i].例如,要遍历data.node的所有子级,请执行以下操作:

for (var i = 0; i < data.node.children.length; i++) {
  //for example call get_path of the child
  var path = $(\'#jstree_demo_div\').jstree(true).get_path(data.node.children[i],"/");
}

我希望我对你的理解是正确的,这就是你所要寻找的.

您可以使用children_d获取该节点的所有子节点.甚至是孩子们的孩子.

for (var i = 0; i < data.node.children_d.length; i++) {
  //for example call get_path of the child
  var path = $(\'#jstree_demo_div\').jstree(true).get_path(data.node.children_d[i],"/");
}

希望这次我对你说对了.请让我知道是否可以.

I'm trying to get the path of the parent and children nodes when the parent is selected. To get the path of the node selected I did the following:

 $("#jstree_demo_div").jstree({
    "core" : {
       "data" : {
          "type" : "POST",
          "url" : "myurl.php",
          "data" : function (node) {
                  return { "id" : node.id };
              }
       },
       "dataType" : "json",
    },
    "plugins" : [ "wholerow", "checkbox", "types" ]
 })
 .on("changed.jstree", function (e, data) {
    var path = $("#jstree_demo_div").jstree(true).get_path(data.node,"/");
    console.log ("path = " + path + "\n");
 });""

But I don't know how to get the path the children's parent.

I tried to get the id's of children's parent and then apply the split()function to get the id's and then apply the get_path() but this is not working, because it said that split is not a function.

var test = data.node.children;
var spt_tst = test.split(',');
alert("node = " + spt_tst[0]);

What am I doing wrong?

**** EDIT ****

My tree is like in the image:

What I want to do is: select the folder images and the get the path of all the content, for example, I want to get the path of the things that are inside .xvpics folder and the others too. Because I will have to send these paths to an .txt file.

解决方案

data.node.childrenreturns an array, which you can access by index. To get the i-th element use data.node.children[i]. For example, to iterate over all children of data.nodedo this:

for (var i = 0; i < data.node.children.length; i++) {
  //for example call get_path of the child
  var path = $(\'#jstree_demo_div\').jstree(true).get_path(data.node.children[i],"/");
}

I hope I understood you right and that is what you are looking for.

EDIT: You can use children_d to get all children of the node. Even the children of the children.

for (var i = 0; i < data.node.children_d.length; i++) {
  //for example call get_path of the child
  var path = $(\'#jstree_demo_div\').jstree(true).get_path(data.node.children_d[i],"/");
}

Hope I got you right this time. Just let me know if not.

这篇关于在jstree中选择父级时如何获取子级路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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