diff options
Diffstat (limited to 'files/ru/web/api/idbindex/locale/index.html')
-rw-r--r-- | files/ru/web/api/idbindex/locale/index.html | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/files/ru/web/api/idbindex/locale/index.html b/files/ru/web/api/idbindex/locale/index.html new file mode 100644 index 0000000000..943e5a1ffe --- /dev/null +++ b/files/ru/web/api/idbindex/locale/index.html @@ -0,0 +1,76 @@ +--- +title: IDBIndex.locale +slug: Web/API/IDBIndex/locale +translation_of: Web/API/IDBIndex/locale +--- +<div>{{APIRef("IndexedDB")}}{{SeeCompatTable}}</div> + +<p>The <strong><code>locale</code></strong> read-only property of the {{domxref("IDBIndex")}} interface returns the locale of the index (for example <code>en-US</code>, or <code>pl</code>) if it had a <code>locale</code> value specified upon its creation (see <a href="https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/createIndex#Parameters"><code>createIndex()</code>'s optionalParameters</a>.) Note that this property always returns the current locale being used in this index, in other words, it never returns <code>"auto"</code>.</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="brush: js">var myIndex = objectStore.index('index'); +console.log(myIndex.locale);</pre> + +<h3 id="Value">Value</h3> + +<p>A {{domxref("DOMString")}}.</p> + +<h2 id="Example">Example</h2> + +<p>In the following example we open a transaction and an object store, then get the index <code>lName</code> from a simple contacts database. We then open a basic cursor on the index using {{domxref("IDBIndex.openCursor")}} — this works the same as opening a cursor directly on an <code>ObjectStore</code> using {{domxref("IDBObjectStore.openCursor")}} except that the returned records are sorted based on the index, not the primary key.</p> + +<p>The <code>locale</code> value is logged to the console.</p> + +<pre class="brush:js">function displayDataByIndex() { + tableEntry.innerHTML = ''; + var transaction = db.transaction(['contactsList'], 'readonly'); + var objectStore = transaction.objectStore('contactsList'); + + var myIndex = objectStore.index('lName'); + console.log(myIndex.locale); + + 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('Entries all displayed.'); + } + }; +};</pre> + +<h2 id="Specification">Specification</h2> + +<p>Not currently part of any specification.</p> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div> + + +<p>{{Compat("api.IDBIndex.locale")}}</p> +</div> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB">Using IndexedDB</a></li> + <li>Starting transactions: {{domxref("IDBDatabase")}}</li> + <li>Using transactions: {{domxref("IDBTransaction")}}</li> + <li>Setting a range of keys: {{domxref("IDBKeyRange")}}</li> + <li>Retrieving and making changes to your data: {{domxref("IDBObjectStore")}}</li> + <li>Using cursors: {{domxref("IDBCursor")}}</li> + <li>Reference example: <a class="external" href="https://github.com/mdn/to-do-notifications/tree/gh-pages">To-do Notifications</a> (<a class="external" href="http://mdn.github.io/to-do-notifications/">view example live</a>.)</li> +</ul> |