mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
23 lines
402 B
JavaScript
23 lines
402 B
JavaScript
|
/* eslint no-useless-escape: 0*/
|
||
|
|
||
|
function nestedPath(items, itemId) {
|
||
|
const idToItem = {};
|
||
|
for (let i = 0; i < items.length; i++) {
|
||
|
idToItem[items[i].id] = items[i];
|
||
|
}
|
||
|
|
||
|
const path = [];
|
||
|
while (itemId) {
|
||
|
const item = idToItem[itemId];
|
||
|
if (!item) break; // Shouldn't happen
|
||
|
path.push(item);
|
||
|
itemId = item.parent_id;
|
||
|
}
|
||
|
|
||
|
path.reverse();
|
||
|
|
||
|
return path;
|
||
|
}
|
||
|
|
||
|
module.exports = { nestedPath };
|