Select to view content in your preferred language

How to expand the tree item of the last item added to MapSwitcher?

650
1
02-04-2013 09:42 AM
DougBrowning
MVP Esteemed Contributor
I want the last map service name added to the TOC MapSwitcherWidget to expand after the map/layer is added.

I can get all of them to expand using this
this.toc.expandLayerItems();


But I have tried all kinds of code to get that last item added to open but nothing works.  It seems like one of these should work but it does not.
toc.expandChildrenOf(toc.firstVisibleItem,true); 
toc.expandItem(toc.firstVisibleItem,true);

Forgot to add tried this also
this.toc.openItems.push(toc.firstVisibleItem);


Any ideas?

Thanks.
Tags (2)
0 Kudos
1 Reply
DougBrowning
MVP Esteemed Contributor
Well I found out the trick was to call toc.validateNow(); before making the calls to .expandItem.  Also my call did not seem to have enough arguments.

But another question is there any documentation on the .expandItem call?  I want to know what all those true values are for. 

I also want to make sure I am using it to collapse correctly.  I tried all false like this and it works but not sure what it all might be doing toc.expandItem(toc.dataProvider.source,false,false,false,null);






--------
Here is my full code.

toc.validateNow();
    var i:int;
    for (i = 0; i < toc.dataProvider.source.length; i++)
    {
     if (toc.dataProvider.source.label == mapStr)
     {
      toc.expandItem(toc.dataProvider.source,true,true,true,null);
      toc.validateNow();
      var j:int;
      for (j = 0; j < toc.dataProvider.source.children.length; j++)
      {
       if (toc.dataProvider.source.children.layerInfo.name == grpStr)
       {
       
       
        //toc.expandChildrenOf(toc.dataProvider.source,true);
        toc.expandItem(toc.dataProvider.source.children,true,true,true,null);
       }
       else if (toc.dataProvider.source.children.layerInfo.name == layerStr)
       {
      
        toc.expandItem(toc.dataProvider.source.children,true,true,true,null);
       }
      }
     }
     else toc.expandItem(toc.dataProvider.source,false,false,false,null);
     toc.validateNow();
     {
     
     }
    }
    toc.validateNow();
0 Kudos