我试图通过将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?
答案 0 :(得分:0)
我得到了答案。示例中提取的变量和节点的id是其中之一。
var nodeElement = getNodeByClickedBtn(this);
var action = this.getAttribute("data-action");
var id = nodeElement.getAttribute("data-node-id");
var node = orgChart.nodes[id];