1

rxjs で n レベルのツリービューを構築しようとしています。私はプレーンなJavaScriptで同じことを達成しました。ここでjsコードを見つけます

var x = [{"id":1,"name":"Admin","parentDepartmentId":null},{"id":2,"name":"Development","parentDepartmentId":1},{"id":3,"name":"Research and Development","parentDepartmentId":1},{"id":4,"name":"FE","parentDepartmentId":2},{"id":5,"name":"BE","parentDepartmentId":2},{"id":6,"name":"Testing","parentDepartmentId":1},{"id":7,"name":"Unit Test","parentDepartmentId":6},{"id":8,"name":"Integration Test","parentDepartmentId":6},{"id":9,"name":"HR","parentDepartmentId":null}];

function getRecords(parents) {
    parents.forEach((parent) => {
      var result = getChildData(parent);
      parent.items = result;
      if (result.length > 0) {
        getRecords(result);
      }
    })
  return parents;
}
  
function getChildData(parent) {
    return x.filter(record => record.parentDepartmentId == parent.id)
}

function getParents(x){
    return  x.filter(record => record.parentDepartmentId == null);
}

var parents = getParents(x)
var result = getRecords(parents);
console.log(result);

誰かがこれにいくつかの光を示すことができますか.

4

1 に答える 1