I have a jQuery plugin that displays an organization chart based off a <ul>
heirarchy.
This will allow my users to drag and drop employees around, and once dropped, an event fires telling me the DOM has changed. At this point I want to read the <ul>
, and build a JSON class off it so I can send it to my server (ASP .NET MVC) for further processing.
Are there any libraries out there that can do this for me, and if not, how would I go about doing it myself?
An example of the html:
<ul id="org" style="display:none">
<li>
Food
<ul>
<li>Beer</li>
<li>Vegetables
<ul>
<li>Pumpkin</li>
<li><a href="http://tquila.com" target="_blank">Aubergine</a></li>
</ul>
</li>
<li>Bread</li>
<li>Chocolate
<ul>
<li>Topdeck</li>
<li>Reese's Cups</li>
</ul>
</li>
</ul>
</li>
</ul>
and- tags with something else? Hmmm. Now I'm wondering if I can't just parse this as xml?
– Daniel Minnaar Oct 01 '15 at 07:24` with `[` and `- ` with `{`. Likewise, close them by replacing `
` with `]` and `` with `}`. Surround your inner text of each element with a surrounding `'`. Note: This doesn't cater for classes, ids or other attributes of the elements you're replacing (i.e. your replace won't match `` if it's `
– Oct 01 '15 at 07:31`. This doesn't really matter if your example is accurate, since you don't have any (apart from the root, which you can just replace altogether by working with the `innerHTML` instead of `outerHTML` or `#org')`. I also didn't mention `:`.