ztree node assignment to obtain node information

Posted by JBWebWorks on Fri, 15 Nov 2019 16:13:48 +0100

Requirement: when clicking a node, assign a value to the node to obtain and display all the information in the clicked tree node.

 

Picture.png


1: before the add or delete interface pops up, assign a value to the node, get the information in the node, and then do the next logic.
$("#toUpdateBtn").attr("sid", treeNode.id);
$("#deleteBtn").attr("sid", treeNode.id);

 

Add this code to the right-click event‘

// Right click event
    function onRightClick(event, treeId, treeNode) {
        document.oncontextmenu = function() {
            return false;
        }
        if (treeNode.id == "1") {
            return;
        }

        // Node assignment
        $("#toUpdateBtn").attr("sid", treeNode.id);
        $("#deleteBtn").attr("sid", treeNode.id);

        showContextMenu(140, event.clientY - 60);
    }

2: when the editing node interface is opened, VAR id = $("taupdatebtn"). Attr ("Sid");

// Editing information
    $("#toUpdateBtn").on("click", function() {
        
        $("#treeContextMenu").hide();
        var id = $("#toUpdateBtn").attr("sid");
        layer.open({
            type : 2,
            title : 'Editing information',
            area : [ '1000px', '650px' ],
            fix : false, // �
            content : basePath + '/design/detain/toUpd?id='+id,
            end : function() {
                initTree();
            }
        });
    });

3: when deleting node information, VAR id = $("ාdeletebtn"). Attr ("Sid");

$("#deleteBtn").on("click", function() {
        $("#treeContextMenu").hide();
        if (!confirm("Confirm to delete"))
            return;

        var id = $("#deleteBtn").attr("sid");

        $.ajax({
            url : basePath + "/design/detain/deleteNode",
            data : {
                "id" : id,
            },
            type : "get",
            success : function(data) {
                initTree();
            }
        });
        deleteDetain(id);
    });

Original author: miss qiche

Pay attention to the public address of "programming micro magazine", reply back to "receive resources", get IT resources and small program 500G dry goods.

 

Topics: Front-end Programming