Bonjour, Bien que sélectionné le "Candidat1" et que mon code me donne la somme de la colonne "vue" soit 30
Ma database :
![](https://static.wixstatic.com/media/5ed4c5_85af6b48a6fb49d78bf8bc2324b559d0~mv2.png/v1/fill/w_980,h_614,al_c,q_90,usm_0.66_1.00_0.01,enc_auto/5ed4c5_85af6b48a6fb49d78bf8bc2324b559d0~mv2.png)
Mon problème auquel je n'arrive pas à trouver la solution réside dans le fait que mon code ne me filtre pas le candidat sélectionné mais me donne les 2 candidats.
Mon code :
export function Validation_click(event) {
// Réinitialiser le champ "inputShowVue" $w('#inputShowVue').value = "";
// Filtrer le résultat de la recherche wixData.query('ContenuMembre') .eq("nomDeFamille", $w('#barreDeRecherche').value) .find() .then(result => { $w('#listRepeater').data = result.items; $w('#listRepeater').show(); });
// Définir les valeurs let iMail = $w('#inputMail').value; const filtre = wixData.filter().contains('candidat', iMail)
// calculer le nombre de visite du candidat toutes catégories
setTimeout(() => {
wixData.aggregate('visites') .filter(filtre) .group('candidat') .sum('vue') .run() .then((results) => { if(results.items.length >0){ let Items = results.items; let Length = results.length; console.log(Items) // --> // Affichage de : console.log(Items) //0: {...} //_id: "Identifiant1" //vueSum: 1 //candidat: "Candidat1" //1: {...} //_id: "Identifiant2" //vueSum: 30 //candidat: "candidat2" console.log(Length) // --> 2 } }) .catch( (error) => { let errorMsg = error.message; let code = error.code; console.log(errorMsg, code) }); }, 500);
De plus, je ne sais pas comment afficher le résultat de cette requête dans $w('#inputShowVue').value.
Merci pour votre aide.
Indeed, the search was configured with something other than candidate1. I corrected my mistake.
I removed the "group" and I solved my problem in order to display the result by doing:
if(results.items.length >0){ let Items = results.items[0].vueSum } let nomVues = results.items[0].vueSum; $w('#inputShowVue').value = "" + nomVues;
My problem is solved and thank you for your precious help.
When you use .contains(), the search/matching is case insensitive and doesn't have to be exact. If 'iMail' = 'candidat', then it will match all your records. Use console.log($w('#inputMail').value) when setting up the filter, to see what the filter is being set to. If you use .eq() then the search IS case sensitive and must match exactly. I suspect the search query is being setup with something other than 'Candidat1', which is why you are getting zero, or nothing returned when using .eq().
Because you are setting up your filter to sum for 1 candidate only and you want the total of all vues, your wixData.aggregate function does not need the .group('candidat') line.
Ok, thanks for the google translate tip.
When I use ".eq", "_Id and item" are empty.
Otherwise 30 for candidate 1 is fine what I want to get because I want to be able to display it on his page.
Mais dans cet etat, ce je sais pas comment le récupérer. Je pense que cela me serais plus facile si mon filtre ne me proposait que ce candidat comme je lui demande ici : let iMail = $w('#inputMail').value.
Merci
Just a reminder that per our Community Guidelines, all posts and comments must be in English so that everyone in the community can understand them.
If you don't speak English, please use Google Translate before posting.
Est-ce qu'il me manque quelque chose?
Vous avez 2 enregistrements pour 'candidat1'. Premier enregistrement = 10, deuxième enregistrement est 20.
10 + 20 = 30 ???
Je vois que vous récupérez 2 enregistrements du résultat de la somme. Hmm, ne devriez-vous pas seulement en récupérer un pour 'candidat1'
Pourquoi avez-vous utilisé .contains(), plutôt que .eq()?
(J'ai utilisé google translate).
English:
What am I missing?
You have 2 registrations for 'candidate1'.
First record = 10, second record = 20.
10 + 20 = 30 ???
I see that you are getting 2 records from the aggregate result of sum().
Hmm, shouldn't you just get one for 'candidat1'.
Why did you use the .contains(), rather than .eq() when defining your filter?
When you use .contains, the search/matching is case insensitive and doesn't have to be exact. If 'iMail' = 'candidat', then it will match all your records. Use console_log, to see what the filter is being set to.
Because you are setting up your filter to sum for 1 candidate only and you want the total of all vues, your wixData.aggregate function does not need the .group('candidat') line.