I'm trying to filter out some body of data from my mongoDB collection with the li data-filter. I have never done this is thus inexperienced. My code doesn't work, please check it out and lend me a hand.
(function ($) {
"use strict";
// Porfolio isotope and filter
$(window).on('load', function () {
var portfolioIsotope = $('.portfolio-container').isotope({
itemSelector: '.portfolio-item'
});
$('#portfolio-filter li').on( 'click', function() {
$("#portfolio-filter li").removeClass('filter-active');
$(this).addClass('filter-active');
$("#portfolio-filter li button").removeClass('btn-primary');
$(this).children('button').addClass('btn-primary');
portfolioIsotope.isotope({ filter: $(this).data('filter') });
});
});
})(jQuery);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="col-lg-12 col-md-12 col-sm-12 col-10">
<ul id="portfolio-filter">
<li data-filter="*" class="filter-active"><button>Everything</button> </li>
<% categories.forEach(cat => { %>
<li data-filter=".filter-<% cat.name %>"><button><%= cat.formal %></button></li>
<% }); %>
</ul>
</div>
<div class="portfolio-container row d-flex d-flex justify-content-center center">
<% if(noMatch && noMatch.length > 0){ %>
<div class="alert alert-danger" style="height: 50px;" role="alert">
<h1 style="font-size: 20.8px;"> <%= noMatch %> </h1>
</div>
<% }; %>
<% let count = 0; %>
<% projects.forEach((project) => { %>
<% count = count === 3 ? 0 : count; %>
<div class="col-lg-6 col-md-6 col-sm-6 col-10 mb-4 <%= project.categories ? project.categories.split(' ').map(el=>'filter-'+el).join(' ') : 'null' %>" data-wow-delay="0.<%= count %>s">
<div class="card card h-100 border-0 shadow rounded-0">
<div class="card-img-top">
<p class="card-title mt-0 mb-0 grid-style" > <i class="bar"></i> <%= project.name %></p>
<div class="embed-responsive-item">
<a href="/projects/<%= project.slug %>">
<img src="<%= project.image %>" alt="" class="img-fluid w-100" />
</a>
</div>
</div>
</div>
</div>
<% count++; %>
<% }); %>
I also have a isotope.pkgd.js library which i chose not to include in the code posted. I also have a categories.js file with which consists of an object with key-value pairs (name: - formal:). This file is also correctly required in my app.js. Only place I haven't done any changes in is my routes/project.js but this is because I have no idea what kind of changes I'd have to do there. Appreciate all the help i can get!