I can't seem to get list.js to filter items with multiple categories

bjornmeansbear

I'm using list.js to sort a list of items by category. It's easy to make work if each list item only fits in one category, but I am struggling with making this sort correctly if something is assigned more than one category.

This is what I have so far on Codepen.io

Basically, I want to be able to tag things with both beverage AND game. I'm obviously not cycling through the array I've created for each item's categories correctly... So it only ever acknowledges the first item?

There isn't much help in the docs of List.js as to how to use it in this manner. I found an issue the list.js maintainer marked as closed that seemed related, but he basically just told the person to ask for help over here, so that's what I'm trying. https://github.com/javve/list.js/issues/189

David Mårtensson

I think this is the problem

for (var i=0, j=tryThis.length; i<j; i++) {
  if (tryThis[i] == selection) {
    return true;
  } else {
    return false;
  }
}

If the first category fits, you return true, but if the first does not fit you immediately return false, preventing any more compares.

You should not return false within the loop but only after the loop, when you know that no category was a match.

===== UPDATE

featureList.filter(function(item) {

This call, does it change the list, or does it return the filtered list?

If it returns the filtered list (as is the usual way) you never saves the returned values?

To save values returned from a filter function you usually just assign the return value.

list = list.filter(function(i) { });

If this works in this case depends on the design of the filter function, but try it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Where can I get a list of categories?

From Dev

Docx: can't seem to get a bulleted list to render

From Dev

Can't seem to get my list view to open from a button

From Dev

python can't seem to get a list to return properly

From Dev

I can't seem to get a working synchronization script with WinSCP

From Dev

I can't seem to get --py-files on Spark to work

From Dev

I can't seem to get this else statement to work in php

From Dev

I can't seem to get jquery variables to preserve their value

From Dev

in an AVD I can't seem to get the sdcard to work

From Dev

I can't seem to get my program to print the shortest word

From Dev

I can't seem to get my background video to play in the background

From Dev

I can't seem to get my query times down

From Dev

I can't seem to get my html button tag to work?

From Dev

Can't create nested list because list.Clear doesn't seem to work as I want

From Dev

Superscrollorama - How can I animate multiple list items?

From Dev

Can't display the description of a list of sub categories

From Dev

Can I use filter in ng-repeat to filter multiple items for a specific field

From Dev

In C#, how can I get the top items that are properties of a list?

From Dev

How can I get list selected items in sencha touch 2.3.1

From Dev

How can i get all list items with Selenium Webdriver?

From Dev

How can I get list of all items with query received?

From Dev

How can I get list items in SharePoint using REST API?

From Dev

Apply multiple filter categories to a list of <li>(s) with javascript

From Dev

I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

From Dev

I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

From Dev

How can I get all categories in dbpedia?

From Dev

How can I get all categories in dbpedia?

From Dev

Why I can't add items to the Generic List with indexer?

From Dev

How can I add multiple overlay layers in leaflet.js having three categories at the right top of the map?

Related Related

  1. 1

    Where can I get a list of categories?

  2. 2

    Docx: can't seem to get a bulleted list to render

  3. 3

    Can't seem to get my list view to open from a button

  4. 4

    python can't seem to get a list to return properly

  5. 5

    I can't seem to get a working synchronization script with WinSCP

  6. 6

    I can't seem to get --py-files on Spark to work

  7. 7

    I can't seem to get this else statement to work in php

  8. 8

    I can't seem to get jquery variables to preserve their value

  9. 9

    in an AVD I can't seem to get the sdcard to work

  10. 10

    I can't seem to get my program to print the shortest word

  11. 11

    I can't seem to get my background video to play in the background

  12. 12

    I can't seem to get my query times down

  13. 13

    I can't seem to get my html button tag to work?

  14. 14

    Can't create nested list because list.Clear doesn't seem to work as I want

  15. 15

    Superscrollorama - How can I animate multiple list items?

  16. 16

    Can't display the description of a list of sub categories

  17. 17

    Can I use filter in ng-repeat to filter multiple items for a specific field

  18. 18

    In C#, how can I get the top items that are properties of a list?

  19. 19

    How can I get list selected items in sencha touch 2.3.1

  20. 20

    How can i get all list items with Selenium Webdriver?

  21. 21

    How can I get list of all items with query received?

  22. 22

    How can I get list items in SharePoint using REST API?

  23. 23

    Apply multiple filter categories to a list of <li>(s) with javascript

  24. 24

    I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

  25. 25

    I am trying to use selenium to load a waiting list and click the button, but I can't seem to find the element

  26. 26

    How can I get all categories in dbpedia?

  27. 27

    How can I get all categories in dbpedia?

  28. 28

    Why I can't add items to the Generic List with indexer?

  29. 29

    How can I add multiple overlay layers in leaflet.js having three categories at the right top of the map?

HotTag

Archive