Using cursor.observeChange to notify UI when a record is added. The record type is:
{"ref":"100","status":"inprogress"}
An empty array is initialized:
var arr=[];
To check if the status is in progress and the ref does not exist in any object in arr[], push it to arr:
arr.push(obj);
If the status is complete and the ref already exists in arr[], then delete it from arr[]. Below is what has been attempted:
var arr = [];
function addObject(obj){
if(!arr.some(function(el){return (el.ref === obj.ref)}))
{
arr.push(obj);
}
else if{
arr.splice(el, 1);
}
}
var cursor = TransactionDetails.find({});
cursor.observeChanges({
added: function(id, object) {
if (object.status == "incomplete") {
addObject(object);
Notification.error("added");
}
else if(object.status == "complete") {
addObject(object);
Notification.error("modified");
}
}
});
The above code is not working as expected. How can we add and delete based on these conditions? Any assistance would be appreciated. Thank you!