Friday, 12 October 2018

How to get last active node status preserved or selected as it was before on page load

i have a jstree where i want to get the last active node to intact as it was before by saving last state in localStorage

below image shows on page load i want to get the result:

enter image description here

here is how i'm saving last state to localStorage

var lastClickedData = data.inst.get_json();
 localStorage.setItem('lastnode',JSON.stringify(lastClickedData));

here is jsfiddle: http://jsfiddle.net/2Jg3B/2128/

$(function () {
    $('#jstree').jstree({
        "json_data" : {
            "data" : [
                {
                    "data" : "A node",
                    "metadata" : { id : 23 },
                    "children" : [ "Child 1", "A Child 2" ]
                },
                {
                    "attr" : { "id" : "li.node.id1" },
                    "data" : {
                        "title" : "Long format demo",
                        "attr" : { "href" : "#" }
                    }
                }
            ]
        },
        "plugins" : [ "themes", "json_data", "ui" ]
    });
    
 var highlightAndExpandLastActiveNode = JSON.parse(localStorage.getItem('lastnode'));
       // $('#jstree')  //set last acive node
       console.log(highlightAndExpandLastActiveNode);
    });


 $("#jstree").bind("select_node.jstree", function(evt, data) {

          if (data.inst._get_parent().length <= 0 || data.inst._get_parent() === -1){
            console.log('clicked data', data.inst.get_json());
          } else {
            var lastClickedData = data.inst.get_json();
            localStorage.setItem('lastnode',JSON.stringify(lastClickedData));
          }
    });
    
    
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://old.static.jstree.com/v.1.0pre/jquery.jstree.js"></script>
<div id="jstree">
</div>

please help me thanks in advance!!!!!



from How to get last active node status preserved or selected as it was before on page load

No comments:

Post a Comment