-
Notifications
You must be signed in to change notification settings - Fork 0
/
toro1.js
executable file
·37 lines (33 loc) · 1.07 KB
/
toro1.js
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
33
34
35
36
37
function search(query) {
if (query.trim() === '') {
displayResults([]);
return;
}
fetch('data.json')
.then(response => response.json())
.then(data => {
const results = data.filter(item =>
item.domaine.toLowerCase().includes(query.toLowerCase()) ||
item.filiere.toLowerCase().includes(query.toLowerCase()) ||
item.id.toLowerCase().includes(query.toLowerCase())
);
displayResults(results);
})
.catch(error => console.error('Error fetching data:', error));
}
function displayResults(results) {
const resultsContainer = document.getElementById('results');
resultsContainer.innerHTML = '';
if (results.length === 0) {
resultsContainer.textContent = 'Aucun résultat trouvé.';
} else {
results.forEach(item => {
const resultItem = document.createElement('div');
resultItem.innerHTML = `
<p>${item.filiere}</p>
<p>${item.domaine}</p>
`;
resultsContainer.appendChild(resultItem);
});
}
}