0

将 IndexedDB 用于本地 html5 应用程序,特别是 YDN-DB 包装器,我经常需要使用动态获取的商店名称来查询商店。当商店不存在时,我会遇到一个错误,并且 javascript 执行中止。错误如下所示:

Uncaught ydn.error.ArgumentException: Store "client_store" not found. 

当然,我知道商店不存在,但我怎样才能最好地编写代码来更优雅地“捕捉”这个错误?谢谢你。

4

2 回答 2

1

您可以使用这个小实用功能:

function storeExists(name) {
    var exists = false;

    db.getSchema().stores.forEach(function (store) {
        if (store.name === name) {
            return exists = true;
        }
    });

    return exists;
}

执行

storeExists('client_store');
于 2016-01-18T13:36:40.267 回答
0

The best is you can avoid dynamically changing database schema.

You can also check existence of store name by checking in schema db.getSchema().stores.contains('new store').

于 2014-06-25T23:05:58.760 回答