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/idbrequest/onsuccess/index.html | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 files/ja/web/api/idbrequest/onsuccess/index.html (limited to 'files/ja/web/api/idbrequest/onsuccess') diff --git a/files/ja/web/api/idbrequest/onsuccess/index.html b/files/ja/web/api/idbrequest/onsuccess/index.html new file mode 100644 index 0000000000..536aa9ab81 --- /dev/null +++ b/files/ja/web/api/idbrequest/onsuccess/index.html @@ -0,0 +1,102 @@ +--- +title: IDBRequest.onsuccess +slug: Web/API/IDBRequest/onsuccess +tags: + - API + - Database + - IDBRequest + - IndexedDB + - Property + - Reference + - Storage + - onsuccess +translation_of: Web/API/IDBRequest/onsuccess +--- +

{{ APIRef("IndexedDB") }}

+ +
+

{{domxref("IDBRequest")}} インターフェースのonsuccessイベントハンドラはリクエストの結果が正常に帰ってきた時に着火されるsuccessイベントをハンドリングします。

+ +

イベントハンドラは、type="success"の成功イベントをパラメータとして受け取ります。

+ +

{{AvailableInWorkers}}

+
+ +

構文

+ +
request.onsuccess = function(event) { ... };
+ +

+ +

下記の例は、指定されたレコードタイトルをリクエストします。リクエストのonsuccessイベントハンドラは{{domxref("IDBObjectStore")}} (objectStoreTitleRequest.resultとして利用可能)からレコードを取得し、そのプロパティを更新してオブジェクトストアに書き戻します。

+ +

完全な例は To-do Notifications app (example live)を参照してください。

+ +
var title = "Walk dog";
+
+// いつものようにトランザクションをオープンする
+var objectStore = db.transaction(['toDoList'], "readwrite").objectStore('toDoList');
+
+// title変数の値をタイトルとして持つTo-Doリストオブジェクトを取得する
+var objectStoreTitleRequest = objectStore.get(title);
+
+objectStoreTitleRequest.onsuccess = function() {
+  // resultとして返却されたデータオブジェクトを取得
+  var data = objectStoreTitleRequest.result;
+
+  // データオブジェクトのnotifiedプロパティ値を"yes"に更新する
+  data.notified = "yes";
+
+  // データベースにアイテムを書き戻す別のリクエストを作成する
+  var updateTitleRequest = objectStore.put(data);
+
+  // この新しいリクエストが成功すると、
+  // 表示更新のためにdisplayData()が再度実行される
+  updateTitleRequest.onsuccess = function() {
+    displayData();
+  };
+};
+ +

仕様書

+ + + + + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('IndexedDB', '#widl-IDBRequest-onsuccess', 'onsuccess')}}{{Spec2('IndexedDB')}}
{{SpecName("IndexedDB 2", "#dom-idbrequest-onsuccess", "onsuccess")}}{{Spec2("IndexedDB 2")}}
+ +

ブラウザーの対応

+ +
+ + +

{{Compat("api.IDBRequest.onsuccess")}}

+
+ +

関連情報

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