Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm just guessing here but you can store that tree in an actual tree in your code and then, when clicked you want to navigate you call a function that's called, say, findPath(fromNode, toNode) that function will find the path between the two nodes, one way to do that is with this pseudo code:</p> <pre><code>Define array1; Define array2; loop while flag is false { store fromNode's parent node in array1; store toNode's parent node in array2; loop through array1 { loop through array2 { if array1[i] == array2[j] { flag = true; } } } } path = array1 + reverse(array2); </code></pre> <p>And there is your path.</p> <p><strong>UPDATE:</strong></p> <p>Another solution would be to make each page have something like this pseudo code--I'm starting to really love pseudo code:</p> <pre><code>function checkChildren(targetNode) { loop through children { if children[i] == target { return path; } if children[i].checkChildren == target node { return path; } } } </code></pre> <p>This is very very abstract, it has a lot more details to it and a lot of optimizations, here's what I have in mind:</p> <ul> <li>Pass the path going up the tree to the function so the path can be found directly instead of returning to the calling function.</li> <li>Pass the current calling child to the parents checkChildren so it won't bother checking that child to make checking faster.</li> </ul> <p>I still think i haven't delivered my idea well so I'll try to explain it.</p> <p>Say you're going from pic2 in the gallery to project3 in projects.</p> <p>pic2 would check its children (if any), if it finds the target it goes there, otherwise it calls its parent (gallery)'s checkChildren passing itself to the parent won't bother checking it, and passing itself to the parent in an array so the parent knows what path has been taken.</p> <p>The parent checks its children if any of them is the target, if it is it adds itself and the child to the path array and that's the path.</p> <p>If it none of its direct children is the target then it calls each of its children's checkChildren passing adding itself to the array of the path so that if any of its children finds the target it adds itself and the child to the array and you have your path.</p> <p>If none of the children find the target gallery calls its parent (home page)'s check children passing itself and the adding itself to the array of the path.</p> <p>The homepage checks all its children except gallery using the same method.</p> <p>Alternatively, you can choose not to pass the path as an array but instead just transition to the parent page if none of the children or the children's children match 'cause you're sure the target is not under this page.</p> <p>I hope I made myself clear. I can write checkChildren for you if you want.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload