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
| var todo = document.querySelector('#todo_input'); var send = document.querySelector('#todo_send'); var todoList = document.querySelector('#todo_list'); var dataRef = firebase.database().ref('todos');
send.addEventListener('click', function(e) { var todoContent = { content: todo.value, }; dataRef.push(todoContent); todo.value = ''; });
dataRef.on('value', function(dataSnapshot) { var data = dataSnapshot.val(); var str = '' for (const item in data) { str += `<li data-key="${item}">${data[item].content}</li>`; } todoList.innerHTML = str; });
todo_list.addEventListener('click', function(e) { if (e.target.nodeName === 'LI') { var key = e.target.dataset.key; dataRef.child(key).remove(); } });
|