Alexander Bahl
Alexander Bahl

Reputation: 33

List.js parameter issue

I have created a filter function that allows me to created different filters that react to a click in my application.

function filterList(filterButton, filterClass, filterBy) {
             $(filterButton).on('click', function() {
                 myList.filter(function(item) {
                     if (item.values().filterClass === filterBy) {
                         return true;
                     } else {
                         return false;
                     }
                 });
             });
         }
filterList('#myButton', 'myClass', 'myFilter');

The problem is the filterClass param is not being treated as a param but as the actually class name.

How can I force it to be treated as a parameter?

Thanks!

Upvotes: 0

Views: 37

Answers (1)

Chris O'Kelly
Chris O'Kelly

Reputation: 1893

I'm not 100% sure this is what you are looking for, but you can dynamically access properties by using square bracket style property access rather than dot style. To do so, you would replace:

if (item.values().filterClass === filterBy) {

with:

if (item.values()[filterClass] === filterBy) {

Upvotes: 1

Related Questions