为什么这个IndexedDB放置命令失败?错误:DataError:DOM IDBDatabase异常0 [英] Why is this IndexedDB put command failing? Error: DataError: DOM IDBDatabase Exception 0

查看:455
本文介绍了为什么这个IndexedDB放置命令失败?错误:DataError:DOM IDBDatabase异常0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  {name:John Doe,年龄:21} 

我使用了以下选项:

  {keyPath:id,autoIncrement:true} 

我能够找到该记录,并显示 id = 1 。然而,当我在下面运行这个命令时,它会抛出一个错误:

  var store = db.transaction([employees]] ,readwrite).objectStore(employees); 
var request = store.put({name:John Doe,年龄:32},1);

这会引发:

  DataError:DOM IDBDatabase异常0 

有谁知道错在哪里?我是否错误地指定了键?



更新

IndexedDB spec 指出第二个参数应该被允许:

 接口IDBObjectStore {
...
IDBRequest put(任意值,可选任意键);
...
};

然而,这不起作用,但是确实有效

  store.put({name:John Doe,年龄:32,id:1}); 

这是一个要求的错误。除非我还在做一些不正确的事情。 解决方案

错误意味着(在这里查看完整列表):


数据






对象存储使用内嵌键并提供了键参数。

您正在指定 keypath ,它指示商店使用内嵌键,但是当你指定一个外联键作为第二个参数 put 时,它将失败。


I have successfully added the following to the objectStore when I created it:

{ name: "John Doe", age: 21 }

I used the options:

{ keyPath: "id", autoIncrement: true }

I am able to find that record and it shows the id = 1. However, when I run this command below, it throws an error:

var store = db.transaction( [ "employees" ], "readwrite" ).objectStore( "employees" );
var request = store.put( { name: "John Doe", age: 32 }, 1 );

This throws:

DataError: DOM IDBDatabase Exception 0

Does anyone know what's wrong? Am I specifying the key incorrectly?

Update

The IndexedDB spec states that the second parameter should be allowed:

interface IDBObjectStore {
    ...
    IDBRequest put (any value, optional any key);
    ...
};

However, it doesn't work, but this does work:

store.put( { name: "John Doe", age: 32, id: 1 } );

That is a bug to require that. Unless I'm still doing something incorrectly.

解决方案

The error means (see here for full list):

Data provided to an operation does not meet requirements.

The object store uses in-line keys and the key parameter was provided.

You are specifying a keypath which instruct the store to use in-line keys, but as you specified an out-of-line key as second parameter to put it will fail.

这篇关于为什么这个IndexedDB放置命令失败?错误:DataError:DOM IDBDatabase异常0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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