Wait a while in a function

0

I have this function

function cambiosIngenieria(){

            var devuelto = vm.productosGridOptions.dataSource.data();
            var idDetallelinea;
            devuelto.forEach(function (lineaDevuelto) {
                if (lineaDevuelto.RevisionIngenieria == "Devuelto") {
                    console.log("Es para devolver");
                    idDetallelinea = lineaDevuelto.Id;
                    var _revisionIngenieria = {
                        __metadata: { 'type': 'SP.Data.DetalleLineasListItem' },
                    }
                    _revisionIngenieria.RevisionIngenieria = "Pendiente"
                    var context = getContext("../lists/DetalleLineas");
                    var resultFecha = updateItem("../_api/web/Lists/GetByTitle('DetalleLineas')/getItemById(" + idDetallelinea + ")", context, _revisionIngenieria);
                    //vm.productosGridOptions.dataSource.read()
                }
            });
            vm.productosGridOptions.dataSource.read()

        }

What it does is bring me an array from a Kendo UI grid and update a data in a sharepoint list.

Now what I need to do in the function cambiosIngenieria wait 5 seconds while vm.productosGridOptions.dataSource.read() finish updating the grid and then continue with the process.

Some way to do it.

    
asked by Eduard 26.02.2018 в 13:39
source

1 answer

5

According to the documentation of read() the returned is a promise.

So you can continue to execute your code when it is finished, as they put it in the example:

dataSource.read().then(function() {
  var view = dataSource.view();
  console.log(view[0].ProductName); // displays "Chai"
});
    
answered by 26.02.2018 / 14:50
source