bonjour,
je débute dans le codage j'ai un tableau avec les horaires de chaque personne et je souhaiterais récupérer un tableau pour chaque nom.
je ne sais pas comment faire, j'ai chercher avec .find je vous pose mon code.
//charger BDD
var Datastore = require('nedb'),
db= new Datastore ({filename: "dataCalendar.db", autoload: true});
//recupere les données
db.find({}, function (err, docs) {
console.log("docs", docs);
le console log me renvoie un array du type:
[ {"title":"Cindy","start":"2023-01-27T12:00:00","end":"2023-01-27T15:30:00","repos":"on","vacance":"on","color":"blue","_id":"3SE1OiSojkHXlt3S"} {"title":"Pierre","start":"2023-01-25T09:00:00","end":"2023-01-25T15:30:00","vacance":"on","color":"red","_id":"LjHSjp8I4OonQyWe"} {"title":"Pierre","start":"2023-01-25T9:30:00","end":"2023-01-25T18:00:00","repos":"on","vacance":"on","color":"red","_id":"S7REMM0DikSBrv1m"} {"title":"Pierre","start":"2023-01-27T09:30:00","end":"2023-01-27T11:30:00","vacance":"on","color":"red","_id":"cSaPBcoZ71Olgvrw"} {"title":"Cindy","start":"2023-01-23T11:30:00","end":"2023-01-23T14:00:00","vacance":"on","color":"blue","_id":"sdFHbC2WxZTQfxYG"} {"title":"Jean","start":"2023-01-26T12:30:00","end":"2023-01-26T19:00:00","vacance":"on","color":"black","_id":"uxCShrJXOHU3xVUO"} {"title":"Cindy","start":"2023-01-24T12:30:00","end":"2023-01-24T16:30:00","repos":"on","vacance":"on","color":"blue","_id":"zGwflBtIrB3pZGqD"} ]
et je souhaiterais récupère un tableau diffèrent pour chaque personne.
Hello :)
Alors c'est normal, la fonction find sert à filtrer les éléments, il faut que tu utilises un map ou un each
var Datastore = require('nedb'),
db= new Datastore ({filename: "dataCalendar.db", autoload: true});
// Premiere version
db.map((element) => {
console.log(element)
});
//Deuxieme version
db.each((element) => {
console.log(element)
});
//Troisième version
db.foreach((element) => {
console.log(element)
});
bon j 'avance doucement mais j ai ma boucle foreach qui boucle pluseur fois je ne comprend pourquoi:
db.find({}, function (err, docs) {
//filtre la semaine select
let filteredEvents = docs.filter(function(docs) {
let eventDate = moment(docs.start);
return eventDate.isBetween(currentWeek, nextWeek);
});
console.log(filteredEvents);
var tableRegistre = document.getElementById("dataTable");
var tableRows = tableRegistre.querySelectorAll("thead > tr");
//on supprime les ligne
tableRows.forEach((el, i) => {
if (i > 0) el.parentNode.removeChild(el);
});
/////filtre cindy///
let selectedJohn = [];
filteredEvents.forEach(function(el) {
if (el.title === 'Cindy') {
selectedJohn.push(el);
};
console.log(selectedJohn);
selectedJohn.forEach((el,index) => {
// console.log(selectedJohn);
//creation d'une ligne
var row = tableRegistre.insertRow(index +1);
//creation des cellules
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
//injecter le contenu des cellules
cell1.innerHTML = "test"
cell2.innerHTML = el.start.toString().substring(11, 16) + "-" + el.end.toString().substring(11, 16);
cell3.innerHTML = "test"
cell4.innerHTML = "test"
voici une capture d'ecran normalement j'ai que 5 enregistrement dans le tableau et ils m'en sort 10.
[https://ibb.co/pXdCg8r]