javascript - List.js filtering by data attribute -
i'm using list.js , able filter results data attribute on item. have found code works standard value in options so:
// list.js options var options = { valuenames: [ 'item__name', 'item__value', 'item__wear', 'item__grade', { data: ['id', 'type', 'grade'] } ] }; // initiate list.js var itemlist = new list('itemz', options); var activefilters = []; //filter $('.filter').change(function() { var ischecked = this.checked; var value = $(this).data("value"); if(ischecked){ activefilters.push(value); } else { activefilters.splice(activefilters.indexof(value), 1); } itemlist.filter(function (item) { if(activefilters.length > 0) { return(activefilters.indexof(item.values().item__grade)) > -1; } return true; }); });
item__grade
works fine i'd prefer use data attribute on <li>
i cannot figure out how access data valuenames in same way can standard ones.
essentially need know right syntax can write this:
return(activefilters.indexof(item.values().data['grade'])) > -1;
Comments
Post a Comment