Shai Erera
unread,May 23, 2013, 9:00:41 AM5/23/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ang...@googlegroups.com
Hi
I've read a lot about how to create trees with Angular, but none of the examples I found really helped me achieve what I want.
I'm building a UI widget which lets you drill-down on a taxonomy, e.g.:
Date/
2010/
March/
23
12
April/
1
10
2011/
January/
...
...
The user is first displayed a list of years. He can then choose to expand a year, then displayed a list of months and if he expands a month, he sees dates.
Not all values of year/month/date exist i.e. for a year we're most definitely not going to get back from the taxonomy all the months.
The user also should be able to expand multiple nodes in the hierarchy simultaneously.
My current data model is a JSON record which deliberately keeps the JSON compact, i.e. the above example looks like:
"nodes" : [
{
"path" : [ "Date", "2010", "March" ],
"children" : [
{ "path" : [ "Date", "2010", "March", "23" ] },
{ "path" : [ "Date", "2010", "March", "12" ] },
]
},
{
"path" : [ "Date", "2011" ],
"children" : [
{ "path" : [ "Date", "2011", "January" ] },
{ "path" : [ "Date", "2011", "April" ] },
]
},
...
]
Currently the 'path' array of each child contains the full path from root, because it's easier for me that way to process it in Angular, but I think I can optimize it to e.g. include just the leaf.
I am looking for a way to generate such tree in the UI ... I tried to create a directive which recursively goes over the 'path' array and adds "<ul><li>" tags each time writing the next element in the array until it exhausted it and then it writes the children array in a <ul><li> structure. But it just doesn't work .. I'm guessing I either use the wrong tool (directive) or I'm missing something very basic.
I don't want to build the tree in response to button clicks or any user intervention, just populate the DOM with the right structure --- just as what I'd do if I wrote a javascript function which looks up the <div> and sets its innerHTML. I prefer to use the Angular way as much as possible (and also learn it on the way) :).
Thanks in advance,
Shai