Hi,
I'm currently implementing some client-side functionality to search a WebDataTree, and was hoping to clarify a few details about the tree csom.
The server-side api provides an "AllNodes" property which contains an array of every node already in depth-first order. Is there a similar mechanism provided via the csom? Or would I need to implement my own depth-first search algorithm in this case? This would also be useful if I had a way to uniquely identify a specific node (for example, index in AllNodes array), for easier retrieval later on. If I'm only able to store the node value or relative index, it seems as though I'd need to search through the tree each time I wanted to re-retrieve it.
Thanks,
Rob Quick
Hi Rob,
You are correct the client side object model works differently than the server-side api. Your best option to implement similiar functionality on the client is to implement a depth-first search.
The tree provides a method, resolveItem, which can be used to directly find a node. This method is passed an address which specifies the node. The address of a particular node can be obtained using the _get_address() function of the node.
The attached sample implements a client side traversal of the tree and also uses the resolveItem method to find an element in the tree.
Please let me know if you have any other questions.Valerie
Hi Valerie,
Thanks, this is exactly what I was looking for. Appreciate the sample you provided. Does the server api have a similar way to look up a node by this address value? If not, it would obviously be simple to implement that myself by splitting the string into an array of indices. I only ask because the node "locations" that I'm saving could be used by both client and server side logic. It seems like the best approach is to write these address strings to an element on the page (like a hidden field) to maintain this state.
Thanks again,
Your best option on the server would be to split the string and use the indices in the array. I’ve updated my sample to demonstrate how this can be done.
Please let me know if you have any other questions.
Valerie
I hope the updated sample helped you out. Please let me know if you have any other questions on using the WebDataTree client-side api.
Thanks for providing the additional sample. This clears up my remaining questions. I appreciate all the help.