diff --git a/dsRag/static/tree.html b/dsRag/static/tree.html
index 74d3dc98..c8d1f0e3 100644
--- a/dsRag/static/tree.html
+++ b/dsRag/static/tree.html
@@ -74,15 +74,16 @@
}
function findParentTitle(node) {
+ if (!node || !node.parent_id) return '';
const parent = allNodes.find(n => n.id === node.parent_id);
return parent ? parent.title : '';
}
function findNodeById(nodes, id) {
- for (var i = 0; i < nodes.length; i++) {
- if (nodes[i].id == id) return nodes[i];
- if (nodes[i].children) {
- var found = findNodeById(nodes[i].children, id);
+ for (const node of nodes) {
+ if (node.id === id) return node;
+ if (node.children) {
+ const found = findNodeById(node.children, id);
if (found) return found;
}
}
@@ -241,12 +242,37 @@
confirmBtn.style.borderRadius = '4px';
confirmBtn.style.cursor = 'pointer';
- // 在确定按钮中获取选中的节点
confirmBtn.onclick = function () {
- const selectedNodes = Array.from(container.querySelectorAll('input[type="checkbox"]:checked'))
- .map(checkbox => checkbox.value);
- console.log("选中的节点ID:", selectedNodes); // 添加这行来输出选中内容
- // 这里添加保存选中节点的逻辑
+ const currentNode = findNodeById(treeData, currentNodeId);
+ if (!currentNode) {
+ 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();
};