3
IndexedDBにデータを格納しようとしましたが、問題が発生しました。うまくフォーマットされたJSONデータを追加しようとすると、私はエラーを取得する:IndexedDB - 操作に提供されたデータが要件を満たしていません
以下DataError: Data provided to an operation does not meet requirements.
は私のIndexedDBコードです:
function dbInit(key, value) {
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 6);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id", autoIncrement: true});
var index = store.createIndex("types", "types");
};
open.onsuccess = function() {
// Start a new transaction
var db = open.result;
var tx = db.transaction("MyObjectStore", "readwrite");
var store = tx.objectStore("MyObjectStore");
var index = store.index("types");
// Add some data
store.put(value);
// Close the db when the transaction is done
tx.oncomplete = function() {
db.close();
};
}
}
私があれば、この問題が存在していることに気づいたいくつかの同様の質問を見た後にkeyPathは指定されていませんが、以下ではkeyPathを "id"およびautoIncrement:trueに指定しました。これはkeyPathとして機能する必要があります。
以下は、私が追加しようとしているJSONデータです。 'value'パラメータの下の関数に渡されます。
[{
"code": 1,
"content": "XXX.html",
"scheme": 4,
"type": "XXX"
}, {
"code": 2,
"content": "XXX.html",
"scheme": 6,
"type": "XXX"
}, {
"code": 3,
"content": "XXX.html",
"scheme": 1,
"type": "XXX"
}, {
"code": 4,
"content": "XXX.html",
"scheme": 4,
"type": "XXX"
}]
私はどんなトラブルが表示されません。 [jsfiddle example](https://jsfiddle.net/4o2obfe0/1/)。私はあなたの関数を使用しました。結果の(https://imgur.com/a/E3QWS)スクリーンショットがあります(あなたはChrome DevToolsアプリケーションタブで自分自身を見ることができます)。あなたのJSONもチェックしてください。末尾に ']'の代わりに '}'があります。 –
面白いです。おそらくこれはFirefoxの問題ですか?毎回このエラーが発生します。残念ながら、これはFirefoxアプリケーションであり、Chromeでは実行されません。ちょうどJSONの終わりに気づいた、これはスタックオーバーフローのためのJSONを編集するときのちょうどタイプミスであり、ライブコードの中にある]。 –
hm、プラグインなしのfirefox [同じ結果を得ました](https://imgur.com/a/EGmKz)(OS:Windows 10) –