1 Feb 2010 07:43
Trees and leaf nodes
I have a large tree of documents that I want to display in a dynamic
treeview, but I'm not sure how best to determine whether a given node
has children or not.
Each document has a 'path' element giving it's place in the tree, eg
this following doc has the parent 'AA', which in turn has the top-level
parent 'A'.
doc = {
'_id':'11203',
'path':['A','AA','11203']
...
};
Fetching and displaying the entire tree is simple... this view:
function(doc) { emit(doc.path, doc.display_name); }
emits in lexicographical order, and some php code turns it into a nested
list.
The entire tree is slow to retrieve and display in one go. With jquery
treeview-async, I retrieve and display only the top-level nodes on page
load, then on expanding a node it will call the server with the ID,
asking for children.
I have a view that returns just the immediate children of the given key:
function(doc) {
if (doc.doc_type=='group') {
//Emit the path of the parent...
doc.path.pop();
emit(doc.path, doc.display_name);
}
(Continue reading)
RSS Feed