WinJS SQLite runAsync all 在做其他事情之前 [英] WinJS SQLite runAsync all before doing something else

查看:33
本文介绍了WinJS SQLite runAsync all 在做其他事情之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组在 SQLite 异步方法中运行的 INSERT 语句:

I have a collection of INSERT statements that gets run within a SQLite async method:

SQLite3JS.openAsync(path).then(function (db) {
    $.each(sql, function (idx, item) {
        return db.runAsync(item).done(function complete(xhr) {
            var i = 0;
        });
    });
});

我想要插入集合,然后在成功完成后做一些事情.我试图遵循 then() 承诺,但它们都在 db.runAsync() 被触发之前被调用.

I want the collection to be inserted, then do something after this has completed successfully. I tried to follow through on then() promises, but they all get called before the db.runAsync() gets fired.

有没有干净的方法来做到这一点?基本上,我有一个进度环,应该在所有这些完成后移除,但我无法正确触发它.

Is there a clean way to do this? Basically, I have a progress ring that should be removed once all this has completed, but I cannot get this to fire correctly.

推荐答案

我想你会想要使用 WinJS 的能力来将多个承诺结合在一起...

I think you'll want to use WinJS's ability to join multiple promises together...

SQLite3JS.openAsync(path).then(function (db) {
    var promises = [];
    $.each(sql, function (idx, item) {
        promises.push( db.runAsync(item) );
    });

    return WinJS.Promis.join( promises ).then(
        function success() {
            // all done!
        },
        function error() {
            // something didn't work
        },
    );
});

这篇关于WinJS SQLite runAsync all 在做其他事情之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆