main
HuangHai 3 weeks ago
parent d311e7f068
commit 1c7f7ba960

@ -74,15 +74,16 @@
} }
function findParentTitle(node) { function findParentTitle(node) {
if (!node || !node.parent_id) return '';
const parent = allNodes.find(n => n.id === node.parent_id); const parent = allNodes.find(n => n.id === node.parent_id);
return parent ? parent.title : ''; return parent ? parent.title : '';
} }
function findNodeById(nodes, id) { function findNodeById(nodes, id) {
for (var i = 0; i < nodes.length; i++) { for (const node of nodes) {
if (nodes[i].id == id) return nodes[i]; if (node.id === id) return node;
if (nodes[i].children) { if (node.children) {
var found = findNodeById(nodes[i].children, id); const found = findNodeById(node.children, id);
if (found) return found; if (found) return found;
} }
} }
@ -241,12 +242,37 @@
confirmBtn.style.borderRadius = '4px'; confirmBtn.style.borderRadius = '4px';
confirmBtn.style.cursor = 'pointer'; confirmBtn.style.cursor = 'pointer';
// 在确定按钮中获取选中的节点
confirmBtn.onclick = function () { confirmBtn.onclick = function () {
const selectedNodes = Array.from(container.querySelectorAll('input[type="checkbox"]:checked')) const currentNode = findNodeById(treeData, currentNodeId);
.map(checkbox => checkbox.value); if (!currentNode) {
console.log("选中的节点ID:", selectedNodes); // 添加这行来输出选中内容 console.error('找不到当前节点:', currentNodeId);
// 这里添加保存选中节点的逻辑 return;
}
console.log(`当前操作的二级节点ID: ${currentNodeId}, 名称: ${currentNode.title}`);
const selectedNodes = [];
const checkboxes = container.querySelectorAll('input[type="checkbox"]:checked');
checkboxes.forEach(checkbox => {
const node = findNodeById(treeData, checkbox.value);
if (node) {
selectedNodes.push({
id: node.id,
title: node.title,
parentTitle: node.isParent ? '' : findParentTitle(node)
});
}
});
console.log('选中的先修知识:');
selectedNodes.forEach(node => {
if (node.parentTitle) {
console.log(`ID: ${node.id}, 名称: 【${node.parentTitle}】${node.title}`);
} else {
console.log(`ID: ${node.id}, 名称: ${node.title}`);
}
});
modal.remove(); modal.remove();
}; };

Loading…
Cancel
Save