下面的代码抛出内部Dartium异常。
<!DOCTYPE html>
<html>
<head>
<script type="application/dart">
import 'dart:html';
import 'dart:indexed_db';
import 'dart:math';
Random random = new Random();
void main() {
window.indexedDB.open('myDB', version: 1, onUpgradeNeeded: _initDB).then((Database db) {
Transaction transaction = db.transaction('myStore', 'readwrite');
ObjectStore objectStore = transaction.objectStore('myStore');
Map data = {
'id': 'id' + random.nextInt(1000).toString(),
'name': 'name' + random.nextInt(1000).toString()
};
objectStore.put(data);
});
}
void _initDB(VersionChangeEvent e) {
(e.target as Request).result.createObjectStore('myStore');
}
</script>
<script src="packages/browser/dart.js"></script>
</head>
</html>我向http://www.dartbug.com/14256提交了一个问题,但可能我的代码中有错误?
发布于 2014-09-14 22:52:50
引用的bug表明这是一个错误,但错误消息现在很有用。它不应该报告更有用的消息:
未捕获错误: DataError:对象存储区使用的键不是行外键,没有键生成器,并且未提供键参数。
发布于 2015-01-18 08:37:32
尝试以下操作:
void _initDB(VersionChangeEvent e) {
(e.target as Request).result.createObjectStore('myStore', autoIncrement: true);
}但您需要清除浏览器设置中的数据,新结构才能正常工作(或者可能增加数据库版本号)。
https://stackoverflow.com/questions/19741265
复制相似问题