Я обновляю форму, используя jQuery, и когда я удаляю данные из интерфейса Firestore, они автоматически не отражаются в моем окне просмотра без обновления страницы. Я ищу способ получать обновления данных в режиме реального времени от Cloud Firestore.
//Update button function
$('.save-button').on('click', function (event) {
$('train-table').empty();
event.preventDefault();
//takes in form inputs
var timetable = {
name: $('.name-input').val(),
destination: $('.destination-input').val(),
frequency: $('.frequency-input').val(),
}
// Add new documents with a generated id.
var addDoc = firestore
.collection('train-schedule')
.add({ timetable })
.then(function (ref) {
try {
console.log("Status- Saved with ID: ", ref.id);
} catch (error) {
console.log("Got an error", error);
}
});
});
//get real time updates
getRealTimeUpdates = function () {
trainCollection.onSnapshot(function (snapshot) {
snapshot.forEach(doc => {
var myData = doc.data().timetable;
console.log("Train Id: ", doc.id);
$(".train-table").append(
"<tr><td id='name-col'>" + myData.name +
"<td id='destination-col'>" + myData.destination +
"<td id='frequency-col'>" + myData.frequency + "</td></tr>");
});
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
}
getRealTimeUpdates();
});
Я ожидаю обновления области просмотра при удалении данных из интерфейса Firestore.