0

I am trying to get content from a JSON-object and dynamically built a ordered list with it (nested with sub(sub)items) with JavaScript. For the front-end lay-out I am using JS 'CollapsibleList' (http://code.stephenmorley.org/javascript/collapsible-lists/). In order to get the lay-out rendered right; I need to add the right class to the list item. This went well for some of them but I can't solve how to add the 'collapsibleListClosed' class.

Here you can see the list-item of the ul class added well but the collapsibleListClosed class wasn't added

I guess the sub-sub items also will give some problems with this approach.

The code I used is:

list = $("<ul class='treeView2' id='productTree'>"); 
  for (var i = 0, l = jsonobject.length; i < l; ++i) {
list.append("<li><input type='text' value='" + jsonobject[i].id + "'</input><ul class='collapsibleList'><li class='collapsibleListClosed'>Test");  
                                               }
                                               $("#goo").append(list);
                                   })
                        });

The end-goal is that I for example have some Main items, subitems, sub- subitems and it automatically/dynamically generates the correct lists in the right structure

How can this be fixed please? Thank you!

7
  • This is my current progress: imgur.com/8pVJsLT and the result I want to become: imgur.com/K128Txx . Commented Jul 19, 2017 at 18:08
  • input doesn't have a close tag in HTML, just: <input /> or <input> Commented Jul 19, 2017 at 18:09
  • you are also missing a > at the end of your input. your input tag should look like <input type='text' value='" + jsonobject[i].id + "'> Commented Jul 19, 2017 at 18:27
  • it automatically/dynamically generates the correct lists in the right structure what structure? what have you tried? Commented Jul 19, 2017 at 18:43
  • Thank you for the answers/support! I used the given advise and got a little further but haven't found the solution yet. This is the current list.append code: list.append("<li><input type='text' value='" + jsonobject[i].id + "'> <ul class='collapsibleList'><li class='collapsibleListClosed'>test2</li></ul></li>"); It doesn't assign the collapsiblelistClosed class to the list items of the ul with collapsibleList class. Commented Jul 19, 2017 at 19:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.