Как мы получаем Edit ID соответствующего узла - PullRequest
0 голосов
/ 17 апреля 2019

Я пытаюсь отредактировать узел GetOrgChart, указав ему 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]?

1 Ответ

0 голосов
/ 17 апреля 2019

Я получил свой ответ. Пример извлеченных переменных и идентификатор узла был одним из них.

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