<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Programmatically open node on layerlist 4.x? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/programmatically-open-node-on-layerlist-4-x/m-p/1192580#M77938</link>
    <description>&lt;P&gt;Hey Mike,&lt;/P&gt;&lt;P&gt;I know this is a bit late, but I wanted to add a response here since I was looking to do the same thing and finally came across a solution.&amp;nbsp; Hopefully this helps anyone in the future with similar issues...&lt;/P&gt;&lt;P&gt;This fn recurses over all of the operational items and checks if the layer id matches the passed in id.&amp;nbsp; If it matches, we expand that node and then return back up through the call stack and expand any parents of that node.&amp;nbsp; The optional part I have commented out was a use case of mine which was to hide other results that didn't match the passed in id. (ie. a search input)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function expand(items: __esri.Collection&amp;lt;__esri.ListItem&amp;gt;, id: string | null) {
  for (const item of items.toArray()) {
    if (item.layer.id === id) {
      // Found the searched for node
      item.open = true;
      return true;
    } else if (expand(item.children, id)) {
      // Open the item parent
      item.open = true;
      return true;
    } else {
      /**
       * Optionally hide other layer items that don't fall in the chain
       * Requires: ArcGIS API for JavaScript 4.24
       * @see https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-LayerList-ListItem.html#hidden
       */
      // item.hidden = id ? true : false;
    }
  }
}

// Use the operational items on the layerList class instance
expand(layerList.operationalItems, "some layer id");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 Jul 2022 20:25:18 GMT</pubDate>
    <dc:creator>jfeliciani</dc:creator>
    <dc:date>2022-07-15T20:25:18Z</dc:date>
    <item>
      <title>Programmatically open node on layerlist 4.x?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/programmatically-open-node-on-layerlist-4-x/m-p/1014787#M71322</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Wondering if anyone has an example on how to programmatically open a layer list node?&amp;nbsp; I need to be able to open a group layer (in a dynamic map service -- not sure if that matters) when I make that node visible to show the sublayers within that node.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 18:55:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/programmatically-open-node-on-layerlist-4-x/m-p/1014787#M71322</guid>
      <dc:creator>MichaelSnook</dc:creator>
      <dc:date>2021-01-07T18:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Programmatically open node on layerlist 4.x?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/programmatically-open-node-on-layerlist-4-x/m-p/1192580#M77938</link>
      <description>&lt;P&gt;Hey Mike,&lt;/P&gt;&lt;P&gt;I know this is a bit late, but I wanted to add a response here since I was looking to do the same thing and finally came across a solution.&amp;nbsp; Hopefully this helps anyone in the future with similar issues...&lt;/P&gt;&lt;P&gt;This fn recurses over all of the operational items and checks if the layer id matches the passed in id.&amp;nbsp; If it matches, we expand that node and then return back up through the call stack and expand any parents of that node.&amp;nbsp; The optional part I have commented out was a use case of mine which was to hide other results that didn't match the passed in id. (ie. a search input)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function expand(items: __esri.Collection&amp;lt;__esri.ListItem&amp;gt;, id: string | null) {
  for (const item of items.toArray()) {
    if (item.layer.id === id) {
      // Found the searched for node
      item.open = true;
      return true;
    } else if (expand(item.children, id)) {
      // Open the item parent
      item.open = true;
      return true;
    } else {
      /**
       * Optionally hide other layer items that don't fall in the chain
       * Requires: ArcGIS API for JavaScript 4.24
       * @see https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-LayerList-ListItem.html#hidden
       */
      // item.hidden = id ? true : false;
    }
  }
}

// Use the operational items on the layerList class instance
expand(layerList.operationalItems, "some layer id");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 20:25:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/programmatically-open-node-on-layerlist-4-x/m-p/1192580#M77938</guid>
      <dc:creator>jfeliciani</dc:creator>
      <dc:date>2022-07-15T20:25:18Z</dc:date>
    </item>
  </channel>
</rss>

