-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfirebaseData.js
81 lines (66 loc) · 2.37 KB
/
firebaseData.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.4.0/firebase-app.js'
import {
getFirestore,
collection,
addDoc,
getDocs,
getDoc,
where,
query,
} from 'https://www.gstatic.com/firebasejs/10.4.0/firebase-firestore.js'
// Your web app's Firebase configuration
import firebaseConfig from './firebaseConfig.js'
// Initialize Firebase
const app = initializeApp(firebaseConfig)
const db = getFirestore(app)
//Show Data
document
.getElementById('filter-form')
.addEventListener('submit', async function (event) {
event.preventDefault()
var selectedLanguage = document.getElementById('languageinput').value
var selectedLevel = document.getElementById('levelinput').value
const resultContainer = document.getElementById('result-container')
console.log(selectedLanguage)
console.log(selectedLevel)
// Create a reference to the cities collection
try {
// Retrieve student data and add it to 'result-container'
const querySnapshot = await getDocs(
query(
collection(db, 'question'),
where('questionData.level', '==', selectedLevel),
where('questionData.lang', '==', selectedLanguage)
)
)
querySnapshot.forEach((doc) => {
const studentData = doc.data().questionData
console.log(studentData)
})
const headers = ['Name', 'Level', 'lang']
querySnapshot.forEach((doc) => {
const selectElement = document.createElement('select')
const studentData = doc.data().questionData
const questionText = document.createElement('h3')
questionText.textContent = studentData.question
console.log('Que :')
console.log(studentData.question)
console.log('Option :')
studentData.options.forEach((option) => {
console.log(option)
const optionElement = document.createElement('option')
optionElement.value = option
optionElement.textContent = option
selectElement.appendChild(optionElement)
})
console.log('Append : ')
resultContainer.appendChild(questionText)
resultContainer.appendChild(selectElement)
})
// Append the table to the 'result-container'
} catch (error) {
console.log('Error ' + error)
}
// You may want to add logic to handle errors appropriately.
})
export default firebaseData