State is cleared after refreshing

46 views Asked by At

I am drawing different tree based on user clicked raw so I need to save many states

i am initializing tree as this

$('#keywordTree').jstree({
    'core': {
        'themes': {
            'icons': false
        }
    },
    "plugins": ["state"]
});

treeInit = true; and after user select the row i bind data like this

function drewRelationTree(secondaryCode) {
    $('#keywordTree').jstree(true).settings.core.data = relationTree;
    $('#keywordTree').jstree(true).settings.state.key = secondaryCode;
    $('#keywordTree').jstree(true).refresh();
}

different states work when switching between different rows until i refresh the page. Then when i cling some row the state localStorage is cleared.

So far my working solution is this:

function drewRelationTree(secondaryCode) { $('#keywordTree').jstree(true).settings.core.data = relationTree; $('#keywordTree').jstree(true).settings.state.key = secondaryCode;

var state = $.vakata.storage.get(secondaryCode);

$('#keywordTree').jstree(true).refresh(true);

setTimeout(() => {
    $.vakata.storage.set(secondaryCode, state);

    $('#keywordTree').jstree(true).restore_state();
},100);

}

I noticed state is reset to empty after refresh

enter image description here

0

There are 0 answers