I have a list of inputs with type checkbox, with values that are loaded from a JSON file. I would like to know how to make a filter, so that by clicking on a particular checkbox, the products (which are loaded from another JSON file) are filtered, leaving only the one that has the size chosen in the checkbox.
The only framework I'm using is Jquery
"produto" : [
{
"dados": {
"nome": "Vestido Listrado",
"imgNome": "vestido-listrado",
"data": "Ter, 25 Abr 2017 05:00:00 GMT"
},
"caracteristicas":{
"tamanho": [1,2,3],
"tipo": 1,
"cores": [1,2,3,4,5,6,7,8,9,10]
},
"pagamento":{
"de": null,
"por": 198,
"qtdParcela": 2
},
"link": "img/produtos/vestido-listrado.jpg"
},
{
"dados":{
"nome": "Chapéu Florido",
"imgNome": "chapéu-florido",
"data": "Sun, 23 Oct 2016 12:00:00 GMT"
},
"caracteristicas":{
"tamanho": [5],
"tipo": 1,
"cores": [6]
},
"pagamento":{
"de": null,
"por": 398,
"qtdParcela": 3
},
"link": "img/produtos/chapeu-florido.jpg"
},
And the HTML of the product generated by JS
<piicture class="produtos-organizados">
<img src="img/produtos/vestido-florido.jpg" alt="vestido-florido">
<figcaption>Vestido Florido</figcaption>
<div>
<p>R$ 198</p>
<p>até 2x de 99.00</p>
</div>
<i class="large material-icons">shopping_cart</i>
</piicture>
And the HTML of the list, only the form is filled by JS
<div class="lista-cores">
<div class="espacado">
<button id="btn-cor">Cores</button>
<span class="canto canto-cor">+</span>
<form class="lista-de-cores oculto fadeOut">
<input type="checkbox">Todos<br>
<input type="checkbox">Amarelo<br>
<input type="checkbox">Azul<br>
<input type="checkbox">Branco<br>
<input type="checkbox">Cinza<br>
<input type="checkbox">Laranja<br>
<input type="checkbox">Verde<br>
<input type="checkbox">Vermelho<br>
<input type="checkbox">Preto<br>
<input type="checkbox">Rosa<br>
<input type="checkbox">Vinho<br>
</form>
</div>
</div>
JS to generate the inputs
function listaDeCores(){
var response = JSON.parse(produto.responseText);
var cor = response.cores;
for (var i = 0; i < cor.length; i++) {
var arrayDeCores = response.cores[i].label;
var listaDeCores = $(".lista-de-cores");
var inputText = arrayDeCores;
var inputP = "<p>" + "</p>";
var idP = response.cores[i].id;
var inputDeCores = "<input type='checkbox'>" + inputText;
var srcIdP = $(inputP).attr("class", idP);
srcIdP.append(inputDeCores);
listaDeCores.append(srcIdP);
}};