question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested lists and multiple list.js instances

See original GitHub issue

I have a list with some nested lists inside.

<ul #1>
    <li>Hi</li>
    <li>I'm a</li>
    <li>
            <ul #2>
                    <li>Nested</li>
                    <li>List</li>
            </ul>
    </li>
</ul>

The list items, both nested and top level are dynamic, in that we don’t know how many items you’ll start with. Currently I’m able to sort and search on the top level list with list.js (ul#1), but unable to get the nested lists (ul#2) to work with list.js.

I created a for each statement that should be firing up a new instance of list.js for each of the nested lists:

nestedlist = $(".nested-list-wrapper-div");
$.each(nestedlist, function(index) {
    //Get the id of each wrapper div
    currentWrapperId = this.id;
    //Make a name for the new list object
    listJsObject = 'listJsObject-' + index;

    listJsObject = new List(currentWrapperId, listOptions);
    console.log(listJsObject);
});

In the listOptions I am making sure to specify the correct sort classes and list classes.

If I log listJsObject in the foreach, I see that the correct amount of new listJS objects are created, with properties corresponding to the correct lists.

I’d like to press one button that sorts all the nested lists, but nothing happens.

    <button data-sort="name" class="sort">sort button</button>

Again, I can’t just specify the list.js objects to instantiate or run methods (like some of the examples for multiple lists in github) because the lists are all being created dynamically when the page loads (php) and thus have unpredictable wrapper id’s.

Would appreciate any guidance on this. Does list.js support this kind of behavior? Thanks.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bilalfastiancommented, Nov 8, 2017

@jonathanbell I don’t have the documentation, however if you can share your test project maybe I can help you on that.

1reaction
Veloracommented, Sep 10, 2015

For now as a solution I will hide the existing list structure and populate the container with a new single list of all elements when the search input is selected. Then after the search term is removed and the input looses focus, the initial nested structure will reappear. (Essentially creating a search mode when the input is focused.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can i create a multiple nested list - Stack Overflow
I have managed to display the list, and the sub-lists, however, clicking either one of the expandable items, expands both items and not...
Read more >
Guide to Nested Lists and Best Practices for Storing Multiple ...
Guide to Nested Lists and Best Practices for Storing Multiple Data Types in a Python List. So far in this section, all of...
Read more >
Python | Split nested list into two lists - GeeksforGeeks
Given a nested 2D list, the task is to split the nested list into two lists such that first list contains first elements...
Read more >
AutoCompleteJS » Examples
Basic Usage · Simple List · Nested Lists 1 · Nested Lists 2 · Nested Lists 3 · Multiple Widgets ...
Read more >
Cases for nested lists - Mathematica Stack Exchange
What should I do to obtain the desired results? The second question is how to deal with list with the following structure: {...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found