1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| function chargerFormation(ceSelect) {
"use strict";
console.log("--- début fonction chargerFormation");
console.log("select changé : %o", ceSelect);
// supprime lancien contenu du select id="Idformation"
const selectFormation = document.getElementById("Idformation");
console.log("select idFormation : %o", selectFormation);
selectFormation.textContent = "";
const x = ceSelect.value;
// on va utiliser un fragment de document pour la performance
const fragment = document.createDocumentFragment();
// construit les nouvelles options
const secFormations = lesFormations.filter((obj) => obj.sec === x);
console.log("formations après filtrage : %d", secFormations.length);
for (const formation of secFormations) {
const option = document.createElement("option");
option.value = formation.do;
option.textContent = formation.f;
fragment.appendChild(option);
console.log("créé <option> pour formation %s (value = %s)", formation.f, formation.do);
}
// ajoute le fragment = ajoute toutes les options dun coup
selectFormation.appendChild(fragment);
console.log("--- fin fonction chargerFormation");
} |