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 :: all GlideException#logRootCauses(String) for more detail Cause (1 of 1): class javax.net.ssl.SSLPeerUnverifiedException: Hostname 
Java :: cancel javafx stage exit request 
Java :: Android popBackStack to specific fragment 
Java :: java.lang.ArrayIndexOutOfBoundsException: -1 
Java :: public class BigInteger { public static void main(String args[]) { long p=2147483648; } } 
Java :: how to clear scoreboard with offline players java 
Java :: java Generate parentheses all combinations 
Java :: laravel Please update to at least Node v12.14 
Java :: ArrayList go to value jav 
Java :: linked list introduction 
Java :: remove duplicate string collection in java 
Java :: how to scroll down chrome browser in selenium java 
Java :: jsp form upload file 
Java :: witch dependency is needed for "ArraysUtils" for the Import? 
Java :: spring data elasticsearch aggregation max 
Java :: Error: Could not find or load main class mcp.client.Start Caused by: java.lang.ClassNotFoundException: mcp.client.Start 
Java :: binomial heap implementation java 
Java :: Java TestNG Data provider Provider with multiple variables 
Java :: Could not find com.commercehub.gradle.plugin:gradle-avro-plugin:0.10.0. 
Java :: java cannot resolve the list method 
Java :: make a string bean spring xml 
Java :: java 8 retrieve all list from object into single list and ignore duplicates 
Java :: how to use java code to print with a network printer 
Java :: how to use int 
Java :: data.sql not loading in springboot 
Java :: can abstract class have constructor 
Java :: java arrays method 
Java :: how to delete last array in java 
Java :: java to c++ converter 
Java :: springboot avoid generated security password: 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =