当子数组为空时,树显示展开符号

Tree show expand symbol when children array is empty

我正在使用制表符树 js 库 (http://tabulator.info/)。但是为什么即使 children 数组为空,树也会显示展开符号?这很烦人!这是一个错误吗?

这个:

var tdata = [{id:1, name:"Billy Bob", age:"12", "_children":[]},];

结果:

我找到原因了。您需要从创建 new Tabulator 对象中删除“dataTree:true,”部分。

就目前所见,如果您有一个“_children”数组(即使它是空的)并且您的“dataTree”设置为 true,那么展开按钮将始终可见。

实际上它是在制表符库中打开的 issue ...

所以这里只有一个解决方案或者解决办法,

你可以在没有children(后端)的情况下尽量不提供_children数组 或者在前端用js调整

var tdata = [
  {
    id: 1,
    name: "Billy Bob",
    age: "12",
    _children: []
  }
];

tdata.forEach((e) => {
  if (!e._children.length) delete e._children; //this will delete any empty _children element 
});

这里是一个 working example(它有两行,一行有 children,一行没有,尝试删除 for each 并用它进行实验)