Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to add new nod in dynamic treeview using javascipt

var expandedNodes = [];
var tree = [];

$(function()
{
    $.post("http://localhost:8000/getLevel1", function( data ) 
    {
        var JSObject = JSON.parse(data);

        for (j in JSObject)
            tree.push(JSObject[j]);

        createTree();
    });
});

function createTree(){

    var options = {
        bootstrap2: false, 
        showTags: true,
        levels: 0,
        data: tree,
        expandIcon: 'fa fa-chevron-right',
        collapseIcon: 'fa fa-chevron-down',
        onNodeExpanded: nodeExpand,
        onNodeCollapsed: nodeCollapse,
        onNodeSelected: nodeSelect,
        onNodeUnselected: nodeUnselect
    }
    $('#treeview').treeview(options);
    for (node in expandedNodes)
        $('#treeview').treeview('expandNode', [ expandedNodes[node], { levels: 0, silent: true } ]);
    $('#treeview').treeview('expandNode', 0, { silent: true } );
};


function nodeExpand(event, data)
{
    expandedNodes.push(data.nodeId);
    var requestObject = []
    requestObject.push(data.text);

    var parent, dummy = data;
    while ((parent = $('#treeview').treeview('getParent', dummy.nodeId))["nodeId"] != undefined)
        {
        requestObject.push(parent.text);
        dummy = parent;
    }

    $.post("http://localhost:8000/getNode?param=" + JSON.stringify(requestObject), function(retVal) 
    {
        var JSObject = JSON.parse(retVal);
        var node = findNode(requestObject);
        node.nodes = JSObject;
        createTree();
    });
}

function nodeCollapse(event, data)
{
    var index = expandedNodes.indexOf(data.nodeId);
    if (index > -1) 
        expandedNodes.splice(index, 1);
}

function nodeSelect(event, data)
{
    if (data.state.expanded == true)
        $('#treeview').treeview('collapseNode', data.nodeId);
    else
        $('#treeview').treeview('expandNode', data.nodeId);
    //$('#treeview').treeview('unselectNode', [ data.nodeId, { silent: true } ]);
}

function nodeUnselect(event, data)
{
}

function findNode(array)
{
    var searchIn = tree; //array
    var lastFound = tree;
    for (var i = array.length - 1; i >= 0; i--)
        {
        var obj = searchInObject(searchIn, array[i]);
        searchIn = obj.nodes;
        lastFound = obj;
    }

    return lastFound;
}

function searchInObject(objectArray, string)
{
    for (var index in objectArray)
        if (objectArray[index].text == string)
            return objectArray[index];
}

$(document).ready(function () {
    var trigger = $('.hamburger'),
    overlay = $('.overlay'),
    isClosed = false;
    hamburger_cross();
    $('#wrapper').toggleClass('toggled');

    trigger.click(function () {
        hamburger_cross();      
    });

    function hamburger_cross() {

        if (isClosed == true) {          
            overlay.hide();
            trigger.removeClass('is-open');
            trigger.addClass('is-closed');
            isClosed = false;
            $('#open_arrow').removeClass('fa-chevron-circle-left').addClass('fa-chevron-circle-right');
        } else {   
            overlay.show();
            trigger.removeClass('is-closed');
            trigger.addClass('is-open');
            isClosed = true;
            $('#open_arrow').removeClass('fa-chevron-circle-right').addClass('fa-chevron-circle-left');
        }
    }

    $('[data-toggle="offcanvas"]').click(function () {
        $('#wrapper').toggleClass('toggled');

    });  
});
Comment

PREVIOUS NEXT
Code Example
Java :: Java Stack class empty() method 
Java :: what is assignment in java with example 
Java :: Double And Char In Java 
Java :: least significant bit java 
Java :: writing wehere clause in repository in springboot 
Java :: method reference java 
Java :: save documents on Android 11 site:stackoverflow.com 
Java :: file with line numbers inserted java 
Java :: Statement sql= clsConexion.getConexion().createStatement(); 
Java :: java remove element from list 
Java :: how to put all words from a file in an array java 
Java :: java mockito subclass mocken method 
Java :: string tmp java 
Java :: 4 byte timestamp java 
Java :: Rotate array to left k cells python 
Java :: how to fetch email and get there body content in spring boot 
Java :: uncaught error java.net.sockettimeoutexception failed to connect 
Java :: how to get value from property file in spring xml file 
Java :: comparable interface 
Java :: jav convert array as list to array 
Java :: getcokor from drawable in java android studio 
Java :: Draw an item using System.out.println 
Java :: build cmake gradle 
Java :: float division by zero 
Java :: arraylistof objects 
Java :: Pattern using recursion in Java 
Java :: import claim jwt 
Java :: how to get map with string as key and Arraylist as value in java 
Java :: Access Members of a Class Java 
Java :: how to use protobuf in java 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =