-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.js
More file actions
49 lines (35 loc) · 1.13 KB
/
Copy pathlist.js
File metadata and controls
49 lines (35 loc) · 1.13 KB
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
import { app } from './firebaseConfig.js';
import {
getDatabase,
ref,
onValue,
set,
remove
} from 'https://www.gstatic.com/firebasejs/10.10.0/firebase-database.js';
const db = getDatabase();
const Ref = ref(db, 'Patients/')
onValue(Ref, snapshot => {
const data = snapshot.val();
console.log(data);
const tableBody = document.getElementById('table').querySelector('tbody');
for (var i in data){
const row = document.createElement('tr');
row.innerHTML = `
<td>${data[i].name}</td>
<td>${i}</td>
<td>${data[i].age}</td>
<td>${data[i].gender}</td>
<td>${data[i].room_no}</td>
<td><button class="btn btn-danger delete-button" id = "${i}">Delete</button></td>
`;
tableBody.appendChild(row);
document.querySelectorAll('.delete-button').forEach(button => {
button.addEventListener('click', function() {
const id = this.id;
console.log(id);
remove(ref(db, 'Patients/' + id));
location.reload()
});
});
}
})