Question

I am using JayData with my OData service.

I load entities from service, I list them and there is a way to delete them.

Remove function looks like this:

delete = function (entity) {
    if (confirm("Do you really want to delete this record?")) {
        entity.remove();
        database.saveChanges()
            .then(function () {
                loadEntities();
            });
        }
    };

It works just fine: it deletes entity and reloads data. Thing is, it sends REQUEST to delete data and reloads it while the request is not yet fulfilled and it reloads data with the "soon to be deleted" entity still in there.

How can I know WHEN the deletion is finished?

Was it helpful?

Solution

We have two APIs and you mix them up. First we have JSQL which is similar to LINQ and you can use callback or promise, like:

 database.remove(entity);
 database.saveChanges(function() {
 });

or

 database.remove(entity);
 database.saveChanges()
 .then(function() {
 });

and we have a second API called itemstore api, which is limited in functionality but simpler, no need to use context, saveChanges and you can only use promises

 database.remove(entity)
 .then(function() {
 });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top