[Project_owners] Easiest way to save/restore <tree/> state?

HJ bugs4hj at netscape.net
Wed Feb 8 14:21:18 EST 2006

Eric H. Jung wrote:
> Hi,
> I have a number of template-driven, RDF-based <tree/> elements. They do
> not specify 'dont-build-content'. I haven't found a way to
> "automatically" save and restore the open/closed state of tree
> containers, so unless someone can suggest one to me, I'm going to code
> it manually.
> My question is: what's the best way to maintain the list of open/closed
> containers in an RDF file given that containers can be deleted and
> moved? I was thinking of storing the subject of each open container in
> a click callback:
> tree.addEventListener("click", clickListener, true);
> function clickListener(event) {
>   if (event.detail == 1) {
>     var row = {}, col = {}, childElt = {};
>     this.treeBoxObject
>       .getCellAt(event.clientX, event.clientY, row, col, childElt);
>     if (childElt.value == "twisty" && row.value > -1) {
>       // TODO: save open/close state
>     }
> }
> Any other ideas?


First of all, the trees I use keep track of this without a single 
additional line of code, but maybe I don't fully understand your 
question.  I wonder if you use ID's for your tree. Do you?

BTW: I would use: tree.treeBoxObject.view.isContainerOpen(row);
to get the open state of container ;)

Oh, and do you plan to add a tree observer?

var treeBuilderObserver = {
   onToggleOpenState: function(aRow) {
     do something here

See also: 


More information about the Project_owners mailing list