My menu renders the “selected” array as options. Then when an item is selected it renders it’s branches as the new options.
To keep track of traversal I create an array called select. So if someone picked the 3rd option then the 1st option then the 6th option, select = [3,1,6]
That’s easy enough just pushing the index into the array, my question is how can I use this array to create a reference to the tree?
If select is [3,1,6] I want create a function that results in a reference to tree[3][1][6] also allowing me to traverse backwards by clipping off the last value of the array.
(in coffeescript)
tree:
name: 'name1'
branches:[
name: 'name2'
branches: [
name: 'name3'
branches: [
name: 'name4'
branches:[]
,
name: 'name5'
branches:[]
,
name: 'name6'
branches:[]
]
]
]
current = tree
#when clicked
$('.menu li').on 'click', ()->
select.push($(this).index())
for value in select
current = current+'['+value+']'
#this results in a string, not an actual reference to the tree.
If I understand correctly what you need, changing the last 2 lines with the following should do the trick: