mirror of
https://github.com/TBEDP/datavjs.git
synced 2025-12-08 19:45:52 +00:00
16 lines
434 B
JavaScript
16 lines
434 B
JavaScript
var getTree = function (table, idIndex, pidIndex) {
|
|
var ids = _.pluck(table, idIndex);
|
|
var pids = _.pluck(table, pidIndex);
|
|
var rootIDs = _.difference(pids, ids);
|
|
|
|
var roots = table.filter(function (row) {
|
|
return _.indexOf(rootIDs, row[pidIndex]) !== -1;
|
|
});
|
|
|
|
roots.forEach(function (root) {
|
|
root.childs = table.filter(function (row) {
|
|
return row[pidIndex] === root[idIndex];
|
|
});
|
|
});
|
|
return roots;
|
|
}; |