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/fr/web/api/idbindex/objectstore/index.html | 167 +++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 files/fr/web/api/idbindex/objectstore/index.html (limited to 'files/fr/web/api/idbindex/objectstore') diff --git a/files/fr/web/api/idbindex/objectstore/index.html b/files/fr/web/api/idbindex/objectstore/index.html new file mode 100644 index 0000000000..6f9a8f95f0 --- /dev/null +++ b/files/fr/web/api/idbindex/objectstore/index.html @@ -0,0 +1,167 @@ +--- +title: IDBIndex.objectStore +slug: Web/API/IDBIndex/objectStore +translation_of: Web/API/IDBIndex/objectStore +--- +

{{ APIRef("IndexedDB") }}

+ +
+

La propriètè objectStore de l'interface {{domxref("IDBIndex")}} renvoie un accès au magasin d'objet que référence l'index.

+ +

{{AvailableInWorkers}}

+
+ +

Syntaxe

+ +
var indexObjectStore = myIndex.objectStore;
+ +

Valeur

+ +

Un {{ domxref("IDBObjectStore","accès au magasin d'objet") }}.

+ +

Example

+ +

Dans l'exemple suivant on ouvre une transaction puis un magasin d'objet et enfin l'index lName.

+ +

Le magasin d'objet référencé par l'index est afficher sur la console, quelque chose ressemblant à:

+ +
IDBObjectStore { name: "contactsList", keyPath: "id", indexNames: DOMStringList[7], transaction: IDBTransaction, autoIncrement: false }
+ +

Finalement, On itère sur tous les enregistrements pour en insérer les données dans un tableau HTML. En utilisant la méthode {{domxref("IDBIndex.openCursor")}} qui travaille de la même façon que la méthode {{domxref("IDBObjectStore.openCursor")}} de l'{{domxref("IDBObjectStore","accès")}} au magasin d'objet sauf que les enregistrements sont renvoyés dans l'ordre de l'index et non celui du magasin d'objet.

+ +
function displayDataByIndex() {
+  tableEntry.innerHTML = '';
+
+  //ouvre un transaction
+  var transaction = db.transaction(['contactsList'], 'readonly');
+  //accés au magasin d'objet
+  var objectStore = transaction.objectStore('contactsList');
+
+  //on récupère l'index
+  var myIndex = objectStore.index('lName');
+  //on affiche le magasin d'objet référencé locale sur la console
+  console.log(myIndex.objectStore);
+
+  //un curseur qui itère sur l'index
+  myIndex.openCursor().onsuccess = function(event) {
+    var cursor = event.target.result;
+    if(cursor) {
+      var tableRow = document.createElement('tr');
+      tableRow.innerHTML =   '<td>' + cursor.value.id + '</td>'
+                           + '<td>' + cursor.value.lName + '</td>'
+                           + '<td>' + cursor.value.fName + '</td>'
+                           + '<td>' + cursor.value.jTitle + '</td>'
+                           + '<td>' + cursor.value.company + '</td>'
+                           + '<td>' + cursor.value.eMail + '</td>'
+                           + '<td>' + cursor.value.phone + '</td>'
+                           + '<td>' + cursor.value.age + '</td>';
+      tableEntry.appendChild(tableRow);
+
+      cursor.continue();
+    } else {
+      console.log('Tous les enregistrements ont été affichés.');
+    }
+  };
+};
+ +

Pour un exemple de travail complet, voir notre To-do Notifications app (view example live).

+ +

Spécification

+ + + + + + + + + + + + + + +
SpécificationStatutCommentaire
{{SpecName('IndexedDB', '#widl-IDBIndex-objectStore', 'objectStore')}}{{Spec2('IndexedDB')}} 
+ +

Compatibilité avec les navigateurs

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Support basique23{{property_prefix("webkit")}}
+ 24
10 {{property_prefix("moz")}}
+ {{CompatGeckoDesktop("16.0")}}
10, en partie157.1
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FonctionnalitéAndroidFirefox Mobile (Gecko)Firefox OSIE PhoneOpera MobileSafari Mobile
Support basique4.4{{CompatGeckoMobile("22.0")}}1.0.110228
Disponible dans workers{{CompatVersionUnknown}}{{CompatGeckoMobile("37.0")}}{{CompatVersionUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}{{CompatUnknown}}
+
+ +

Voir aussi

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