mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-18 09:35:20 +02:00
e11e57f1d8
The implementation uses / symbol as a nesting separator. I.e. tag/subtag is a nested tag, where tag is the parent tag and subtag is its child. Creating a tag named tag/subtag/subsubtag creates three tags, one for each level. The tags are associated using parent_id field. In the app, viewing notes with a tag will also show all notes that are associated with any of the tag's descendant tags (same for the note count). Deleting a tag will also delete all its descendant tags. In the desktop app the tags are shown nested just like the notebooks.
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 };
|