From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/ja/web/api/idbcursor/advance/index.html | 130 +++++++++++++++++++++++++ files/ja/web/api/idbcursor/continue/index.html | 129 ++++++++++++++++++++++++ files/ja/web/api/idbcursor/index.html | 128 ++++++++++++++++++++++++ 3 files changed, 387 insertions(+) create mode 100644 files/ja/web/api/idbcursor/advance/index.html create mode 100644 files/ja/web/api/idbcursor/continue/index.html create mode 100644 files/ja/web/api/idbcursor/index.html (limited to 'files/ja/web/api/idbcursor') diff --git a/files/ja/web/api/idbcursor/advance/index.html b/files/ja/web/api/idbcursor/advance/index.html new file mode 100644 index 0000000000..c23a16513a --- /dev/null +++ b/files/ja/web/api/idbcursor/advance/index.html @@ -0,0 +1,130 @@ +--- +title: IDBCursor.advance() +slug: Web/API/IDBCursor/advance +tags: + - API + - Database + - IDBCursor + - IndexedDB + - Method + - Reference + - Storage + - advance +translation_of: Web/API/IDBCursor/advance +--- +

{{APIRef("IndexedDB")}}

+ +

{{domxref("IDBCursor")}} インターフェイスの advance() メソッドはカーソルが位置を前進させる回数をセットします。

+ +

{{AvailableInWorkers}}

+ +

構文

+ +
cursor.advance(count);
+ +

パラメータ

+ +
+
count
+
カーソルが前進する回数
+
+ +

戻り値

+ +

{{jsxref('undefined')}}

+ +

例外

+ +

このメソッドは次のいずれかの {{domxref("DOMException")}} を発生することがあります:

+ + + + + + + + + + + + + + + + + + + + + + +
例外説明
TransactionInactiveErrorこの IDBCursor のトランザクションは活性化していません。
TypeErrorcount パラメーターに渡された値がゼロや負の数です。
InvalidStateErrorカーソルは現在繰り返し中か、最後を過ぎています。
+  
+ +

+ +

このシンプルな断片でトランザクションを作成し、オブジェクトストアを取得し、オブジェクトストアのレコードを一通り繰り返すカーソルを使っています。ここで cursor.advance(2) を使ってそれぞれ 2 回前進していて、つまり 1 つおきの結果だけが表示されます。advance() は {{domxref("IDBCursor.continue")}} と同様に動作しますが、常に次のレコードに移動するのでなく、一度に複数のレコードを飛び越えられるのが違います。

+ +

注意点としてループの繰り返しで、カーソルオブジェクトの現在のレコードのテータを cursor.value.fooを使って取得できます。完全な動作例は、IDBCursor の例(ライブ例を見る)を見てください。

+ +
function advanceResult() {
+  list.innerHTML = '';
+  var transaction = db.transaction(['rushAlbumList'], "readonly");
+  var objectStore = transaction.objectStore('rushAlbumList');
+
+  objectStore.openCursor().onsuccess = function(event) {
+    var cursor = event.target.result;
+    if(cursor) {
+      var listItem = document.createElement('li');
+      listItem.innerHTML = '<strong>' + cursor.value.albumTitle + '</strong>, ' + cursor.value.year;
+      list.appendChild(listItem);
+      cursor.advance(2);
+    } else {
+      console.log('Every other entry displayed.');
+    }
+  };
+};
+ +

仕様

+ + + + + + + + + + + + + + + + + + + +
仕様書策定状況コメント
{{SpecName('IndexedDB', '#widl-IDBCursor-advance-void-unsigned-long-count', 'advance()')}}{{Spec2('IndexedDB')}} 
{{SpecName("IndexedDB 2", "#dom-idbcursor-advance", "advance()")}}{{Spec2("IndexedDB 2")}} 
+ +

ブラウザー実装状況

+ +
+
+ + +

{{Compat("api.IDBCursor.advance")}}

+
+
+ +

関連情報

+ + diff --git a/files/ja/web/api/idbcursor/continue/index.html b/files/ja/web/api/idbcursor/continue/index.html new file mode 100644 index 0000000000..eb671e3487 --- /dev/null +++ b/files/ja/web/api/idbcursor/continue/index.html @@ -0,0 +1,129 @@ +--- +title: IDBCursor.continue() +slug: Web/API/IDBCursor/continue +tags: + - API + - Database + - IDBCursor + - IndexedDB + - Reference + - continue + - ストレージ + - メソッド +translation_of: Web/API/IDBCursor/continue +--- +
{{APIRef("IndexedDB")}}
+ +

continue() は {{domxref("IDBCursor")}} インターフェースのメソッドで、カーソルを現在の方向に次の位置、任意のキーパラメーターに一致するキーを持つアイテムまで進めます。キーを指定しない場合、カーソルはその方向に基づいて、すぐ隣の位置へ進みます。

+ +

{{AvailableInWorkers}}

+ +

構文

+ +
cursor.continue(key);
+ +

引数

+ +
+
key {{optional_inline}}
+
カーソルを進めるためのキーです。
+
+ +

例外

+ +

このメソッドは次の内いずれかの {{domxref("DOMException")}} を発生させることがあります。

+ + + + + + + + + + + + + + + + + + + + + + +
例外解説
TransactionInactiveErrorこの IDBCursor のトランザクションがアクティブではありません。
DataError +

キーパラメーターが以下の状態のうちのいずれかである可能性があります。

+ +
    +
  • キーが妥当なキーではない
  • +
  • キーがこのカーソルの位置と同じかそれより小さく、カーソルの方向が next または nextunique である
  • +
  • キーがこのカーソルの位置と同じかそれより大きく、カーソルの方向が prev または prevunique である
  • +
+
InvalidStateErrorカーソルが現在走査中または末尾を越えて走査しました。
+ +

+ +

この単純で部分的な実例ではトランザクションを作り、オブジェクトストアを取得した後、オブジェクトストア内の全ての反復処理するためカーソルを使用しています。カーソルはキーに基づいてデータを選択するには必要ありません。その全てを捕らえることができます。また、それぞれのループ内での繰り返しでカーソルオブジェクトを用い、 cursor.value.foo とすることで、現在のレコードからカーソルの下のデータを取得できることには注目です。完全な例については IDBCursor の例 (ライブデモを見る) を参照してください。

+ +
function displayData() {
+  var transaction = db.transaction(['rushAlbumList'], "readonly");
+  var objectStore = transaction.objectStore('rushAlbumList');
+
+  objectStore.openCursor().onsuccess = function(event) {
+    var cursor = event.target.result;
+    if(cursor) {
+      var listItem = document.createElement('li');
+      listItem.innerHTML = cursor.value.albumTitle + ', ' + cursor.value.year;
+      list.appendChild(listItem);
+
+      cursor.continue();
+    } else {
+      console.log('Entries all displayed.');
+    }
+  };
+};
+ +

仕様書

+ + + + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('IndexedDB', '#widl-IDBCursor-continue-void-any-key', 'continue()')}}{{Spec2('IndexedDB')}}
{{SpecName("IndexedDB 2", "#dom-idbcursor-continue", "continue()")}}{{Spec2("IndexedDB 2")}}
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.IDBCursor.continue")}}

+ +

関連情報

+ + diff --git a/files/ja/web/api/idbcursor/index.html b/files/ja/web/api/idbcursor/index.html new file mode 100644 index 0000000000..7b024be836 --- /dev/null +++ b/files/ja/web/api/idbcursor/index.html @@ -0,0 +1,128 @@ +--- +title: IDBCursor +slug: Web/API/IDBCursor +tags: + - API + - Database + - IDBCursor + - IndexedDB + - Interface + - NeedsTranslation + - Reference + - Storage + - TopicStub +translation_of: Web/API/IDBCursor +--- +

{{APIRef("IndexedDB")}}

+ +

IndexedDB APIIDBCursor インターフェイスはデータベースの複数レコードを横断したり繰り返すためのカーソルです。

+ +

このカーソルはどのインデックスやオブジェクトをループしているかを示す元です。これは範囲内の位置を示す持ち、レコードのキー順に増/減して動きます。カーソルはアプリケーションからカーソル範囲内の全レコードに非同期に処理できるようにします。

+ +

一度に無制限の数のカーソルを持つことができます。あるカーソルを表す同一の IDBCursor オブジェクトを取得できます。操作はインデックスやオブジェクトストアに対して実行されます。

+ +

{{AvailableInWorkers}}

+ +

プロパティ

+ +
+
{{domxref("IDBCursor.source")}} {{readonlyInline}}
+
カーソルが繰り返している{{domxref("IDBObjectStore")}} か {{domxref("IDBIndex")}} を返します。この関数は、カーソルが現在繰り返されていたり、繰り返しが終わりを過ぎたり、トランザクションがアクティブでなくても、null や例外を返しません。
+
{{domxref("IDBCursor.direction")}} {{readonlyInline}}
+
カーソルの横断の向きを返します。取りうる値については Constants を見てください。
+
{{domxref("IDBCursor.key")}} {{readonlyInline}}
+
カーソル位置のレコードのキーを返します。カーソルが範囲外の場合、undefined にセットされます。カーソルキーはあらゆるデータ型となりえます。
+
{{domxref("IDBCursor.value")}} {{readonlyInline}}
+
カーソル位置のレコードの値を返します。カーソルの値はあらゆるデータ型となりえます。
+
{{domxref("IDBCursor.primaryKey")}} {{readonlyInline}}
+
カーソルの現在有効な主キーを返します。カーソルが現在繰り返されていたり範囲外で繰り返されていた場合、これは undefined にセットされます。カーソルの主キーはあらゆるデータ型となりえます。
+
+ +

メソッド

+ +
+
{{domxref("IDBCursor.advance()")}}
+
Sets the number times a cursor should move its position forward.
+
{{domxref("IDBCursor.continue()")}}
+
Advances the cursor to the next position along its direction, to the item whose key matches the optional key parameter.
+
{{domxref("IDBCursor.continuePrimaryKey()")}}
+
Sets the cursor to the given index key and primary key given as arguments.
+
{{domxref("IDBCursor.delete()")}}
+
Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, deletes the record at the cursor's position, without changing the cursor's position. This can be used to delete specific records.
+
{{domxref("IDBCursor.update()")}}
+
Returns an {{domxref("IDBRequest")}} object, and, in a separate thread, updates the value at the current position of the cursor in the object store. This can be used to update specific records.
+
+ +

Constants

+ +
{{ deprecated_header(13) }}
+ +
+

これらの constants は利用できません — Gecko 25 で削除されました。代わりに直接 string constants を使う必要があります。({{ bug(891944) }})

+
+ + + +

+ +

In this simple fragment we create a transaction, retrieve an object store, then use a cursor to iterate through all the records in the object store. The cursor does not require us to select the data based on a key; we can just grab all of it. Also note that in each iteration of the loop, you can grab data from the current record under the cursor object using cursor.value.foo. For a complete working example, see our IDBCursor example (view example live.)

+ +
function displayData() {
+  var transaction = db.transaction(['rushAlbumList'], "readonly");
+  var objectStore = transaction.objectStore('rushAlbumList');
+
+  objectStore.openCursor().onsuccess = function(event) {
+    var cursor = event.target.result;
+    if(cursor) {
+      var listItem = document.createElement('li');
+      listItem.innerHTML = cursor.value.albumTitle + ', ' + cursor.value.year;
+      list.appendChild(listItem);
+
+      cursor.continue();
+    } else {
+      console.log('Entries all displayed.');
+    }
+  };
+}
+ +

仕様

+ + + + + + + + + + + + + + +
仕様書策定状況コメント
{{SpecName('IndexedDB', '#idl-def-IDBCursor', 'cursor')}}{{Spec2('IndexedDB')}} 
+ +

ブラウザー実装状況

+ +
+ + +

{{Compat("api.IDBCursor")}}

+
+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf