From 5a2459b924f88e8a39afcb9bbe8d423c7997b240 Mon Sep 17 00:00:00 2001 From: Amandine Arias Date: Mon, 31 May 2021 12:19:02 +0200 Subject: [PATCH] work in progress (fetch API) : index filtred by multiple tags (#2) --- js/home_page.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/js/home_page.js b/js/home_page.js index 15b1071..1115efa 100644 --- a/js/home_page.js +++ b/js/home_page.js @@ -46,19 +46,22 @@ function fetchData() { console.log(tagsList); // pour chaque tag du tableau - tagsList.forEach((tag) => { + tagsList.filter((tag) => { // affiche photographe(s) dont tag(s) correspond(ent) for (let j = 0; j < data.photographers.length; j++) { + // liste des tags de chaque photographe console.log(data.photographers[j].tags); + // tag choisi = tag photographe - let selectedTags = data.photographers[j].tags.some( + const selectedTags = data.photographers[j].tags.some( // let selectedTags = data.photographers[j].tags.map( // let selectedTags = data.photographers[j].tags.filter( (elmt) => elmt == tag ); + // tag choisi = tag photographe > true / false - console.log(selectedTags); + console.log(selectedTags == photographersTags[j]); // si tag(s) choisi(s) if (selectedTags) { @@ -66,6 +69,11 @@ function fetchData() { setPhotographers(data.photographers[j]); } } + + // AFFICHE TOUS LES PHOTOGRAPHES SI AUCUN TAG N'EST CHOISI + // ----- NE FONCTIONNE PAS ----- // + // if (tagsList.length = 0) setPhotographers(data.photographers[j]); + }); }); }