Javascript 递归存储父节点';标题到根

Javascript 递归存储父节点';标题到根,javascript,jquery,fancytree,Javascript,Jquery,Fancytree,我有一张像这样的桌子: 因此,任何不是文件夹的条目都有相应的输入标记。现在我正在为renderColumn方法中的输入设置name属性,如下所示: const node = data.node; const $tdList = $(node.tr).find('>td'); if (node.isFolder()) { $tdList.eq(1).empty(); } else { const $input = $tdList.eq(1).find('input'); $in

我有一张像这样的桌子:

因此,任何不是文件夹的条目都有相应的输入标记。现在我正在为
renderColumn
方法中的输入设置
name
属性,如下所示:

const node = data.node;
const $tdList = $(node.tr).find('>td');

if (node.isFolder()) {
  $tdList.eq(1).empty();
} else {
  const $input = $tdList.eq(1).find('input');
  $input.attr('name', `${node.parent.title}_${node.title}`);
  $input.attr('value', node.data.value);
}

但它所做的只是有效地存储父级的标题。是否有任何方法可以递归地将所有家长的标题存储到root,例如,在
version
列中,我输入了
input[name=“categoryCell\uu version”]
,然后在
backgroundColor
-
categoryCell\u configuration\u backgroundColor
中,您可以递归地执行此操作

function buildTitle(node) {
  if (node.parent.className !== 'alex-node`) { // just an example, change the condition to something else
    return '';
  } else {
    return buildTitle(node.parent) + node.parent.title + '__';
  }
}

(您需要修剪下划线,但这相当简单)

您可以递归执行

function buildTitle(node) {
  if (node.parent.className !== 'alex-node`) { // just an example, change the condition to something else
    return '';
  } else {
    return buildTitle(node.parent) + node.parent.title + '__';
  }
}

(您需要修剪下划线,但这相当简单)

非常感谢!多谢各位!