Note that there are some explanatory texts on larger screens.

plurals
  1. POTurning list of urls into a navigation pane
    primarykey
    data
    text
    <p>I have a list of sites and sites within those sites. How do I create a navigation tree using ul and li elements given this output? </p> <pre><code>https://hosted.demo.ca https://hosted.demo.ca/academic https://hosted.demo.ca/academic/bm https://hosted.demo.ca/academic/cmtte https://hosted.demo.ca/academic/dm https://hosted.demo.ca/academic/pm https://hosted.demo.ca/archive https://hosted.demo.ca/associations https://hosted.demo.ca/associations/bm https://hosted.demo.ca/associations/dm https://hosted.demo.ca/associations/pm https://hosted.demo.ca/cdn https://hosted.demo.ca/cf_test https://hosted.demo.ca/charity https://hosted.demo.ca/charity/bod https://hosted.demo.ca/charity/bod/boarddocs https://hosted.demo.ca/charity/bod/mtgmaterial https://hosted.demo.ca/clite https://hosted.demo.ca/clite/admin https://hosted.demo.ca/company https://hosted.demo.ca/company/finance https://hosted.demo.ca/company/hr https://hosted.demo.ca/company/hr/b1 https://hosted.demo.ca/company/hr/b1/b2 https://hosted.demo.ca/company/hr/b1/b2/b3 https://hosted.demo.ca/company/mrkting https://hosted.demo.ca/demo </code></pre> <p>I want to take this list and turn it into something like this: </p> <pre><code>&lt;UL&gt; &lt;li&gt;Academic &lt;ul&gt; &lt;li&gt;BM&lt;/li&gt; &lt;li&gt;CMTTE&lt;/LI&gt; &lt;li&gt;DM&lt;/li&gt; &lt;li&gt;PM&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;ARCHIVE&lt;/li&gt; &lt;/UL&gt; &lt;ul&gt; &lt;LI&gt;ASSOCIATIONS &lt;ul&gt; &lt;li&gt;BM&lt;/li&gt; &lt;li&gt;DM&lt;/LI&gt; &lt;li&gt;PM&lt;/li&gt; &lt;/ul&gt; &lt;/LI&gt; &lt;/ul&gt; </code></pre> <p>Someone suggested I try something like this: </p> <pre><code> var map = {}; //init the map var web = $(xData.responseXML).find("Web"); for (var i = 0; i &lt; web.length; i++) { //we create a index for our links based on the depth of them by `/` var m = web[i].attributes['Url'].value.substring(23, web[i].attributes['Url'].value.length).split('/').length; map[m] = map[m] || []; //make sure we leave alone the old values if there is none init with new array map[m].push(web[i].attributes['Url'].value); //push new value to node } console.log(map); </code></pre> <p>But the object it returned took all sites with the same number of "/" and put them in one array. Which isn't exactly what I'm looking for. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload