ObjectStore放置语法

时间:2013-03-04 11:12:39

标签: dart dart-html

我在使用idb.ObjectStore.put的新语法(r18915)时遇到问题。有人可以帮忙吗? 示例如下所示导致错误如下:

AsyncError: ‘Error:DataError: DOM IDBDatabase Exception 0’
Stack trace: #0 ObjectStore._put_2(file:///E:/b/build/slave/dartium-win-full-trunk/build/src/build/Release/obj/
global_intermediate/webkit/bindings/dart/indexed_db/ObjectStore.dart:141:3) #1
  ObjectStore.$dom_put(file:///E:/b/build/slave/dartium-win-full-trunc/build/src/build/Release/obj/
global_intermediate/webkit/bindings/dart/indexed_db/ObjectStore.dart:137:18) #2
  ObjectStore.put(file:///E:/b/build/slave/dartium-win-full-trunc/build/src/build/Release/obj/
global_intermediate/webkit/bindings/dart/indexed_db/ObjectStore.dart:9:27)

我正在使用的代码正在运行但已针对新版本进行了修改,如下所示:

Future fDbAddOrUpdateClient(String sKey1, ClassClientData clClientData) { 
  idb.Transaction oDbTxn         = ogDb1.transaction(sgStoreClient, 'readwrite');
  idb.ObjectStore oDbStoreClient = oDbTxn.objectStore(sgStoreClient);

  Completer completer = new Completer();
  var oDbReqPut = oDbStoreClient.put(
        {'sKey': sKey1,
         'sNameTitle'  : clClientData.sNameTitle, 
         'sNameFamily' : clClientData.sNameFamily,
         'sNameGiven1' : clClientData.sNameGiven1,
         'sNameGiven2' : clClientData.sNameGiven2
         })
         .then((val){
           completer.complete(val);
           return;
         })
         .catchError((e){
           window.alert("${e}");
           return;
         });
}

2 个答案:

答案 0 :(得分:0)

除了将来你指定你的函数返回但从来没有,只有一个完整的值(如其他注释中所述),未来的语法看起来是正确的。错误本身实际上表明传递给objectstore.put命令的数据无效。

IndexedDB Exceptions。您可能需要验证传递给地图的数据。

答案 1 :(得分:0)

感谢您的帮助。主要问题似乎是数据库没有打开或没有相关的东西,比如没有创建ObjectStore,但没有显示错误。

希望以下是更好的代码(r19425):

  Future future = fDbAddOrUpdateClient(sKey, clClientData)
   .catchError((oError) => window.alert("${oError}"));
}

Future fDbAddOrUpdateClient(String sKey1, ClassClientData clClientData) { 
  idb.Transaction oDbTxn         = ogDb1.transaction(sgStoreClient, 'readwrite');
  idb.ObjectStore oDbStoreClient = oDbTxn.objectStore(sgStoreClient);

  return oDbStoreClient.put(fMapClient(sKey1, clClientData));
}