Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is demo for it: <a href="http://jsfiddle.net/zn2C7/7/" rel="nofollow">http://jsfiddle.net/zn2C7/7/</a></p> <pre><code> var list = $("&lt;ul&gt;"); function populatedata() { $.each(data.FolderList, function (i, folder) { if (folder.ParentFolderID == -1) { var item = $("&lt;li&gt;").html(folder.FolderName); list.append(item); var children = $('&lt;ul&gt;'); item.append(children); checkChild(folder.FolderID, children); } }); $('body').append(list); } function checkChild(parentid, parent) { $.each(data.FolderList, function (i, folder) { if (folder.ParentFolderID == parentid) { var item = $("&lt;li&gt;").html(folder.FolderName); var children = $('&lt;ul&gt;'); parent.append(item); item.append(children); checkChild(folder.FolderID, children); } else { return ; } }); } </code></pre> <p>It was possible to build it using html variable, like you tried to do that, but it is much simpler to use DOM manipulation functions of jQuery (<code>$('&lt;ul&gt;')</code> and <code>$('&lt;li&gt;')</code> - create new element, <a href="http://api.jquery.com/append/" rel="nofollow"><code>.append()</code></a> - append element to some other element)</p> <pre><code>function checkChild(parentid) { $.each(data.FolderList, function (i, folder) { if (folder.ParentFolderID == parentid) { html += '&lt;li&gt;&lt;ul&gt;' + folder.FolderName; checkChild(folder.FolderID); html+=&lt;/ul&gt;&lt;/li&gt; return html; } else { return ; } }); } </code></pre> <p>Also, please note that in code above you are doing <code>return html;</code> from <code>each</code> function callback. Not sure what you wanted to get exactly, but in <a href="http://api.jquery.com/each/" rel="nofollow"><code>.each</code></a> it may work like <code>break</code> in regular loop (if you will return false):</p> <blockquote> <p>We can stop the loop from within the callback function by returning false.</p> </blockquote> <p>That is from jquery api page.</p> <p>Also, for such tasks I prefer to use debugger. At this moment there are a lot of powerful tools for HTML/CSS/JS debugging in browser. Just press <kbd>F12</kbd> in Chrome, IE or FF (for the last one you may need to install Firebug extension) and you will get a lot of helpful features along with simple JS debugging. </p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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