我们如何获取相应节点的编辑 ID



我正在尝试通过将GetOrgChart节点指向需要相应节点ID才能工作的URL来编辑该节点。我被困在这里,希望找到解决方案。我的代码如下

                getOrgChart.themes.monica.box += '<g transform="matrix(1,0,0,1,350,10)">'
                        + btnAdd
                        + btnEdit
                        + btnDel
                        + '</g>';
                        var orgChart = new getOrgChart(chartElement, {
                            scale: 0.5,
                            theme: "monica",
                            primaryFields: resp2.primaryFields,
                            photoFields: [resp2.photoField],
                            enableZoom: true,
                            enableEdit: true,
                            enableDetailsView: true,
                            dataSource: processed
                        });    
                function getNodeByClickedBtn(el) {
                    while (el.parentNode) {
                        el = el.parentNode;
                        if (el.getAttribute("data-node-id"))
                            return el;
                    }
                    return null;
                }
                var init = function () {
                    var btns = document.getElementsByClassName("btn");
                    for (var i = 0; i < btns.length; i++) {
                        btns[i].addEventListener("click", function () {                  
                            var nodeElement = getNodeByClickedBtn(this);
                            var action = this.getAttribute("data-action");
                            var id = nodeElement.getAttribute("data-node-id");
                            var node = orgChart.nodes[id];
                            switch (action) {
                                case "add":
                                    window.location.href='${request.contextPath}' + resp2.addLink;
                                    break;
                                case "edit":
                                    //console.log('&id=' + processed['id']);
                                    //    return;
                                    window.location.href='${request.contextPath}' + resp2.editLink + '&id=' + resp.data[]['id'];
 break;
   case "delete":
                                    window.location.href='${request.contextPath}' + resp2.deleteLink;
                                    break;
                            }
                        });
                    }
                }
                init();
                        },
                        error: function (ex) {
                            console.log(ex);
                        }
                    });
                },
                error: function (ex) {
                    console.log(ex);
                }
            });

问题代码在这里

 case "edit":
//console.log('&id=' + processed['id']);
//    return;
                                    window.location.href='${request.contextPath}' + resp2.editLink + '&id=' + resp.data[]['id'];
                                    break;

我应该怎么做才能访问 resp.data[index] 变量中的 id?

我得到了答案。示例提取的变量和节点的 id 就是其中之一。

var nodeElement = getNodeByClickedBtn(this);
                            var action = this.getAttribute("data-action");
                            var id = nodeElement.getAttribute("data-node-id");
                            var node = orgChart.nodes[id];

最新更新