Complete path from the root node in Javascript Fancy tree












4














I am using Fancy tree to populate the tree, for understanding the code is shown



 var treeData = [{"title":"image_test","folder":true,"children":[{"title":"images5","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images4","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images3","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images2","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images1","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]}]}];


$(function(){
$("#tree3").fancytree({
// extensions: ["select"],
checkbox: true,
selectMode: 3,
source: treeData,
select: function(event, data) {
// Get a list of all selected nodes, and convert to a key array:
var selKeys = $.map(data.tree.getSelectedNodes(), function(node){
return node.key;
});
$("#echoSelection3").text(selKeys.join(", "));

// Get a list of all selected TOP nodes
var selRootNodes = data.tree.getSelectedNodes(true);
// ... and convert to a key array:
var selRootKeys = $.map(selRootNodes, function(node){
return node.key;
});
$("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
$("#echoSelectionRoots3").text(selRootNodes.join(", "));
},
dblclick: function(event, data) {
data.node.toggleSelected();
},
keydown: function(event, data) {
if( event.which === 32 ) {
data.node.toggleSelected();
return false;
}
},
// The following options are only required, if we have more than one tree on one page:
// initId: "treeData",
cookieId: "fancytree-Cb3",
idPrefix: "fancytree-Cb3-"
});
});


The div used is tree3.



<div id="tree3"></div>
<div>Selected keys: <span id="echoSelection3">-</span></div>
<div>Selected root keys: <span id="echoSelectionRootKeys3">-</span></div>
<div>Selected root nodes: <span id="echoSelectionRoots3">-</span></div></div>


Now i want that whenever the user checks the childnode the name of the parent node until the root node is also shown for this i have used



var selRootNodes = data.tree.getSelectedNodes(true);


but was not able to get the result in echoselection as childnode and then until root node



Actually I want to send the selection to the server so that they are saved since they are file paths.



Since I am using population of tree first time so kindly bear with me. If there is any other good option kindly provide.



P.S; I want to send the tree path to server in the form of directory address /abc/acv/ac/xyz.png
image is attached which is not showing image5 and image_test in the selected root nodes










share|improve this question





























    4














    I am using Fancy tree to populate the tree, for understanding the code is shown



     var treeData = [{"title":"image_test","folder":true,"children":[{"title":"images5","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images4","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images3","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images2","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images1","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]}]}];


    $(function(){
    $("#tree3").fancytree({
    // extensions: ["select"],
    checkbox: true,
    selectMode: 3,
    source: treeData,
    select: function(event, data) {
    // Get a list of all selected nodes, and convert to a key array:
    var selKeys = $.map(data.tree.getSelectedNodes(), function(node){
    return node.key;
    });
    $("#echoSelection3").text(selKeys.join(", "));

    // Get a list of all selected TOP nodes
    var selRootNodes = data.tree.getSelectedNodes(true);
    // ... and convert to a key array:
    var selRootKeys = $.map(selRootNodes, function(node){
    return node.key;
    });
    $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
    $("#echoSelectionRoots3").text(selRootNodes.join(", "));
    },
    dblclick: function(event, data) {
    data.node.toggleSelected();
    },
    keydown: function(event, data) {
    if( event.which === 32 ) {
    data.node.toggleSelected();
    return false;
    }
    },
    // The following options are only required, if we have more than one tree on one page:
    // initId: "treeData",
    cookieId: "fancytree-Cb3",
    idPrefix: "fancytree-Cb3-"
    });
    });


    The div used is tree3.



    <div id="tree3"></div>
    <div>Selected keys: <span id="echoSelection3">-</span></div>
    <div>Selected root keys: <span id="echoSelectionRootKeys3">-</span></div>
    <div>Selected root nodes: <span id="echoSelectionRoots3">-</span></div></div>


    Now i want that whenever the user checks the childnode the name of the parent node until the root node is also shown for this i have used



    var selRootNodes = data.tree.getSelectedNodes(true);


    but was not able to get the result in echoselection as childnode and then until root node



    Actually I want to send the selection to the server so that they are saved since they are file paths.



    Since I am using population of tree first time so kindly bear with me. If there is any other good option kindly provide.



    P.S; I want to send the tree path to server in the form of directory address /abc/acv/ac/xyz.png
    image is attached which is not showing image5 and image_test in the selected root nodes










    share|improve this question



























      4












      4








      4


      4





      I am using Fancy tree to populate the tree, for understanding the code is shown



       var treeData = [{"title":"image_test","folder":true,"children":[{"title":"images5","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images4","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images3","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images2","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images1","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]}]}];


      $(function(){
      $("#tree3").fancytree({
      // extensions: ["select"],
      checkbox: true,
      selectMode: 3,
      source: treeData,
      select: function(event, data) {
      // Get a list of all selected nodes, and convert to a key array:
      var selKeys = $.map(data.tree.getSelectedNodes(), function(node){
      return node.key;
      });
      $("#echoSelection3").text(selKeys.join(", "));

      // Get a list of all selected TOP nodes
      var selRootNodes = data.tree.getSelectedNodes(true);
      // ... and convert to a key array:
      var selRootKeys = $.map(selRootNodes, function(node){
      return node.key;
      });
      $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
      $("#echoSelectionRoots3").text(selRootNodes.join(", "));
      },
      dblclick: function(event, data) {
      data.node.toggleSelected();
      },
      keydown: function(event, data) {
      if( event.which === 32 ) {
      data.node.toggleSelected();
      return false;
      }
      },
      // The following options are only required, if we have more than one tree on one page:
      // initId: "treeData",
      cookieId: "fancytree-Cb3",
      idPrefix: "fancytree-Cb3-"
      });
      });


      The div used is tree3.



      <div id="tree3"></div>
      <div>Selected keys: <span id="echoSelection3">-</span></div>
      <div>Selected root keys: <span id="echoSelectionRootKeys3">-</span></div>
      <div>Selected root nodes: <span id="echoSelectionRoots3">-</span></div></div>


      Now i want that whenever the user checks the childnode the name of the parent node until the root node is also shown for this i have used



      var selRootNodes = data.tree.getSelectedNodes(true);


      but was not able to get the result in echoselection as childnode and then until root node



      Actually I want to send the selection to the server so that they are saved since they are file paths.



      Since I am using population of tree first time so kindly bear with me. If there is any other good option kindly provide.



      P.S; I want to send the tree path to server in the form of directory address /abc/acv/ac/xyz.png
      image is attached which is not showing image5 and image_test in the selected root nodes










      share|improve this question















      I am using Fancy tree to populate the tree, for understanding the code is shown



       var treeData = [{"title":"image_test","folder":true,"children":[{"title":"images5","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images4","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images3","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images2","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]},{"title":"images1","folder":true,"children":[{"title":"img_01.png","children":},{"title":"img_02.png","children":},{"title":"img_03.png","children":},{"title":"img_04.png","children":},{"title":"img_05.png","children":},{"title":"img_06.png","children":},{"title":"img_07.png","children":}]}]}];


      $(function(){
      $("#tree3").fancytree({
      // extensions: ["select"],
      checkbox: true,
      selectMode: 3,
      source: treeData,
      select: function(event, data) {
      // Get a list of all selected nodes, and convert to a key array:
      var selKeys = $.map(data.tree.getSelectedNodes(), function(node){
      return node.key;
      });
      $("#echoSelection3").text(selKeys.join(", "));

      // Get a list of all selected TOP nodes
      var selRootNodes = data.tree.getSelectedNodes(true);
      // ... and convert to a key array:
      var selRootKeys = $.map(selRootNodes, function(node){
      return node.key;
      });
      $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
      $("#echoSelectionRoots3").text(selRootNodes.join(", "));
      },
      dblclick: function(event, data) {
      data.node.toggleSelected();
      },
      keydown: function(event, data) {
      if( event.which === 32 ) {
      data.node.toggleSelected();
      return false;
      }
      },
      // The following options are only required, if we have more than one tree on one page:
      // initId: "treeData",
      cookieId: "fancytree-Cb3",
      idPrefix: "fancytree-Cb3-"
      });
      });


      The div used is tree3.



      <div id="tree3"></div>
      <div>Selected keys: <span id="echoSelection3">-</span></div>
      <div>Selected root keys: <span id="echoSelectionRootKeys3">-</span></div>
      <div>Selected root nodes: <span id="echoSelectionRoots3">-</span></div></div>


      Now i want that whenever the user checks the childnode the name of the parent node until the root node is also shown for this i have used



      var selRootNodes = data.tree.getSelectedNodes(true);


      but was not able to get the result in echoselection as childnode and then until root node



      Actually I want to send the selection to the server so that they are saved since they are file paths.



      Since I am using population of tree first time so kindly bear with me. If there is any other good option kindly provide.



      P.S; I want to send the tree path to server in the form of directory address /abc/acv/ac/xyz.png
      image is attached which is not showing image5 and image_test in the selected root nodes







      javascript jquery jquery-ui tree fancytree






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 at 9:33

























      asked Mar 12 '14 at 15:18









      Zeeshan

      41521024




      41521024
























          1 Answer
          1






          active

          oldest

          votes


















          7














          After searching and looking deep into the code i found the solution :



           $(function(){

          var tree3 = $("#tree3").fancytree({
          checkbox: true,
          selectMode: 3,
          source: $.ajax({
          url: "/getlist",
          dataType: "json"
          }),
          select: function(event, data) {

          // Get a list of all selected nodes, and convert to a key array:
          var selKeys =
          $.map(data.tree.getSelectedNodes(), function(node) {
          if(node.key != 0){
          return node.key;
          }
          });

          var rootstructures =
          $.map(selKeys, function(item){
          var tempnode = data.tree.getNodeByKey(item);
          var tempstructure = ;
          tempstructure.push(data.tree.getNodeByKey(item).title);
          while(tempnode.getParent().getParent()){
          tempstructure.push(tempnode.getParent().title);
          tempnode = tempnode.getParent();
          }
          tempstructure.reverse();
          return tempstructure.join('/');
          });

          // WRITE DEBUG OUTPUT TO DIVS

          $("#echoSelectionRoots4").text(rootstructures);
          $("#echoSelection3").text(selKeys.join(", "));

          // Get a list of all selected TOP nodes
          var selRootNodes = data.tree.getSelectedNodes(true);
          // ... and convert to a key array:
          var selRootKeys = $.map(selRootNodes, function(node){
          return node.key;
          });
          $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
          $("#echoSelectionRoots3").text(selRootNodes.join(", "));

          // -----------------

          },
          });
          });


          This implementation works and now on selection the path till root node is populated on the echoSelectionRoots4 object.



          Example Output : /image_test/image5/img_01.png, /image_test/image5/img_02.png etc






          share|improve this answer



















          • 1




            Great, this is exactly what i needed :) but the sourcecode could use a little cleanup, it would be best to remove all the stuff that is irrelevant to the actual problem (keydown, dblclick, ...) and to correct the indention...
            – Larzan
            Jun 14 '14 at 10:43










          • yeah sure, Thanks for the cleanup.. sorry for the laziness :)
            – Zeeshan
            Jun 18 '14 at 15:57






          • 1




            No worries, your code saved me a lot of time, thx :)
            – Larzan
            Jun 18 '14 at 16:03











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22355936%2fcomplete-path-from-the-root-node-in-javascript-fancy-tree%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          7














          After searching and looking deep into the code i found the solution :



           $(function(){

          var tree3 = $("#tree3").fancytree({
          checkbox: true,
          selectMode: 3,
          source: $.ajax({
          url: "/getlist",
          dataType: "json"
          }),
          select: function(event, data) {

          // Get a list of all selected nodes, and convert to a key array:
          var selKeys =
          $.map(data.tree.getSelectedNodes(), function(node) {
          if(node.key != 0){
          return node.key;
          }
          });

          var rootstructures =
          $.map(selKeys, function(item){
          var tempnode = data.tree.getNodeByKey(item);
          var tempstructure = ;
          tempstructure.push(data.tree.getNodeByKey(item).title);
          while(tempnode.getParent().getParent()){
          tempstructure.push(tempnode.getParent().title);
          tempnode = tempnode.getParent();
          }
          tempstructure.reverse();
          return tempstructure.join('/');
          });

          // WRITE DEBUG OUTPUT TO DIVS

          $("#echoSelectionRoots4").text(rootstructures);
          $("#echoSelection3").text(selKeys.join(", "));

          // Get a list of all selected TOP nodes
          var selRootNodes = data.tree.getSelectedNodes(true);
          // ... and convert to a key array:
          var selRootKeys = $.map(selRootNodes, function(node){
          return node.key;
          });
          $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
          $("#echoSelectionRoots3").text(selRootNodes.join(", "));

          // -----------------

          },
          });
          });


          This implementation works and now on selection the path till root node is populated on the echoSelectionRoots4 object.



          Example Output : /image_test/image5/img_01.png, /image_test/image5/img_02.png etc






          share|improve this answer



















          • 1




            Great, this is exactly what i needed :) but the sourcecode could use a little cleanup, it would be best to remove all the stuff that is irrelevant to the actual problem (keydown, dblclick, ...) and to correct the indention...
            – Larzan
            Jun 14 '14 at 10:43










          • yeah sure, Thanks for the cleanup.. sorry for the laziness :)
            – Zeeshan
            Jun 18 '14 at 15:57






          • 1




            No worries, your code saved me a lot of time, thx :)
            – Larzan
            Jun 18 '14 at 16:03
















          7














          After searching and looking deep into the code i found the solution :



           $(function(){

          var tree3 = $("#tree3").fancytree({
          checkbox: true,
          selectMode: 3,
          source: $.ajax({
          url: "/getlist",
          dataType: "json"
          }),
          select: function(event, data) {

          // Get a list of all selected nodes, and convert to a key array:
          var selKeys =
          $.map(data.tree.getSelectedNodes(), function(node) {
          if(node.key != 0){
          return node.key;
          }
          });

          var rootstructures =
          $.map(selKeys, function(item){
          var tempnode = data.tree.getNodeByKey(item);
          var tempstructure = ;
          tempstructure.push(data.tree.getNodeByKey(item).title);
          while(tempnode.getParent().getParent()){
          tempstructure.push(tempnode.getParent().title);
          tempnode = tempnode.getParent();
          }
          tempstructure.reverse();
          return tempstructure.join('/');
          });

          // WRITE DEBUG OUTPUT TO DIVS

          $("#echoSelectionRoots4").text(rootstructures);
          $("#echoSelection3").text(selKeys.join(", "));

          // Get a list of all selected TOP nodes
          var selRootNodes = data.tree.getSelectedNodes(true);
          // ... and convert to a key array:
          var selRootKeys = $.map(selRootNodes, function(node){
          return node.key;
          });
          $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
          $("#echoSelectionRoots3").text(selRootNodes.join(", "));

          // -----------------

          },
          });
          });


          This implementation works and now on selection the path till root node is populated on the echoSelectionRoots4 object.



          Example Output : /image_test/image5/img_01.png, /image_test/image5/img_02.png etc






          share|improve this answer



















          • 1




            Great, this is exactly what i needed :) but the sourcecode could use a little cleanup, it would be best to remove all the stuff that is irrelevant to the actual problem (keydown, dblclick, ...) and to correct the indention...
            – Larzan
            Jun 14 '14 at 10:43










          • yeah sure, Thanks for the cleanup.. sorry for the laziness :)
            – Zeeshan
            Jun 18 '14 at 15:57






          • 1




            No worries, your code saved me a lot of time, thx :)
            – Larzan
            Jun 18 '14 at 16:03














          7












          7








          7






          After searching and looking deep into the code i found the solution :



           $(function(){

          var tree3 = $("#tree3").fancytree({
          checkbox: true,
          selectMode: 3,
          source: $.ajax({
          url: "/getlist",
          dataType: "json"
          }),
          select: function(event, data) {

          // Get a list of all selected nodes, and convert to a key array:
          var selKeys =
          $.map(data.tree.getSelectedNodes(), function(node) {
          if(node.key != 0){
          return node.key;
          }
          });

          var rootstructures =
          $.map(selKeys, function(item){
          var tempnode = data.tree.getNodeByKey(item);
          var tempstructure = ;
          tempstructure.push(data.tree.getNodeByKey(item).title);
          while(tempnode.getParent().getParent()){
          tempstructure.push(tempnode.getParent().title);
          tempnode = tempnode.getParent();
          }
          tempstructure.reverse();
          return tempstructure.join('/');
          });

          // WRITE DEBUG OUTPUT TO DIVS

          $("#echoSelectionRoots4").text(rootstructures);
          $("#echoSelection3").text(selKeys.join(", "));

          // Get a list of all selected TOP nodes
          var selRootNodes = data.tree.getSelectedNodes(true);
          // ... and convert to a key array:
          var selRootKeys = $.map(selRootNodes, function(node){
          return node.key;
          });
          $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
          $("#echoSelectionRoots3").text(selRootNodes.join(", "));

          // -----------------

          },
          });
          });


          This implementation works and now on selection the path till root node is populated on the echoSelectionRoots4 object.



          Example Output : /image_test/image5/img_01.png, /image_test/image5/img_02.png etc






          share|improve this answer














          After searching and looking deep into the code i found the solution :



           $(function(){

          var tree3 = $("#tree3").fancytree({
          checkbox: true,
          selectMode: 3,
          source: $.ajax({
          url: "/getlist",
          dataType: "json"
          }),
          select: function(event, data) {

          // Get a list of all selected nodes, and convert to a key array:
          var selKeys =
          $.map(data.tree.getSelectedNodes(), function(node) {
          if(node.key != 0){
          return node.key;
          }
          });

          var rootstructures =
          $.map(selKeys, function(item){
          var tempnode = data.tree.getNodeByKey(item);
          var tempstructure = ;
          tempstructure.push(data.tree.getNodeByKey(item).title);
          while(tempnode.getParent().getParent()){
          tempstructure.push(tempnode.getParent().title);
          tempnode = tempnode.getParent();
          }
          tempstructure.reverse();
          return tempstructure.join('/');
          });

          // WRITE DEBUG OUTPUT TO DIVS

          $("#echoSelectionRoots4").text(rootstructures);
          $("#echoSelection3").text(selKeys.join(", "));

          // Get a list of all selected TOP nodes
          var selRootNodes = data.tree.getSelectedNodes(true);
          // ... and convert to a key array:
          var selRootKeys = $.map(selRootNodes, function(node){
          return node.key;
          });
          $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
          $("#echoSelectionRoots3").text(selRootNodes.join(", "));

          // -----------------

          },
          });
          });


          This implementation works and now on selection the path till root node is populated on the echoSelectionRoots4 object.



          Example Output : /image_test/image5/img_01.png, /image_test/image5/img_02.png etc







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 18 '14 at 12:13









          Larzan

          5,90632837




          5,90632837










          answered Mar 24 '14 at 14:22









          Zeeshan

          41521024




          41521024








          • 1




            Great, this is exactly what i needed :) but the sourcecode could use a little cleanup, it would be best to remove all the stuff that is irrelevant to the actual problem (keydown, dblclick, ...) and to correct the indention...
            – Larzan
            Jun 14 '14 at 10:43










          • yeah sure, Thanks for the cleanup.. sorry for the laziness :)
            – Zeeshan
            Jun 18 '14 at 15:57






          • 1




            No worries, your code saved me a lot of time, thx :)
            – Larzan
            Jun 18 '14 at 16:03














          • 1




            Great, this is exactly what i needed :) but the sourcecode could use a little cleanup, it would be best to remove all the stuff that is irrelevant to the actual problem (keydown, dblclick, ...) and to correct the indention...
            – Larzan
            Jun 14 '14 at 10:43










          • yeah sure, Thanks for the cleanup.. sorry for the laziness :)
            – Zeeshan
            Jun 18 '14 at 15:57






          • 1




            No worries, your code saved me a lot of time, thx :)
            – Larzan
            Jun 18 '14 at 16:03








          1




          1




          Great, this is exactly what i needed :) but the sourcecode could use a little cleanup, it would be best to remove all the stuff that is irrelevant to the actual problem (keydown, dblclick, ...) and to correct the indention...
          – Larzan
          Jun 14 '14 at 10:43




          Great, this is exactly what i needed :) but the sourcecode could use a little cleanup, it would be best to remove all the stuff that is irrelevant to the actual problem (keydown, dblclick, ...) and to correct the indention...
          – Larzan
          Jun 14 '14 at 10:43












          yeah sure, Thanks for the cleanup.. sorry for the laziness :)
          – Zeeshan
          Jun 18 '14 at 15:57




          yeah sure, Thanks for the cleanup.. sorry for the laziness :)
          – Zeeshan
          Jun 18 '14 at 15:57




          1




          1




          No worries, your code saved me a lot of time, thx :)
          – Larzan
          Jun 18 '14 at 16:03




          No worries, your code saved me a lot of time, thx :)
          – Larzan
          Jun 18 '14 at 16:03


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22355936%2fcomplete-path-from-the-root-node-in-javascript-fancy-tree%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          Refactoring coordinates for Minecraft Pi buildings written in Python