IDBFactory
インターフェイスのcmp()
メソッドは、2つのキーが等価か決定するために比較し、そして、IndexedDBで保存や統合のような操作を命令します。
Note: Do not use this method for comparing arbitrary JavaScript values, because many JavaScript values are either not valid IndexedDB keys (booleans and objects, for example) or are treated as equivalent IndexedDB keys (for example, since IndexedDB ignores arrays with non-numeric properties and treats them as empty arrays, so any non-numeric arrays are treated as equivalent). This throws an exception if either of the values is not a valid key.
構文
var result = window.indexedDB.cmp(a, b);
戻り値
比較結果を示す整数値。 次のテーブルに可能性のある値とその意味を載せます。:
戻り値 | 説明 |
---|---|
-1 | 1つ目のキーが2つ目のキーより小さい |
0 | 1つ目のキーと2つ目のキーが等しい |
1 | 1つ目のキーが2つ目のキーより大きい |
例外
このメソッドでは、次の型のようなDOMError
を持つ DOMException
が発生するかもしれません。
属性 | 説明 |
---|---|
DataError |
渡されたキーが不正な値である。 |
例
var a = 1;
var b = 2;
var result = window.indexedDB.cmp(a, b);
console.log( "Comparison results: " + result );
パラメーター
- first
- 比較する1つ目のキー。
- second
- 比較する2つ目のキー。
仕様
Specification | Status | Comment |
---|---|---|
Indexed Database API cmp の定義 |
勧告 |
ブラウザ実装状況
現在、互換性データを可読形式の JSON フォーマットに置き換えているところです。
この互換性一覧は古い形式を使っており、これに含まれるデータの置き換えが済んでいません。
手助けしていただける場合は、こちらから!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 23webkit 24 |
10 moz 16.0 (16.0) |
10, partial | 15 | 7.1 |
Feature | Android | Firefox Mobile (Gecko) | Firefox OS | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 4.4 | 22.0 (22.0) | 1.0.1 | 10 | 22 | 未サポート |
Chromeは新しい仕様を実装していますが、旧い仕様も実装したままになっているので注意してください。同じように、ベンダプレフィックスなしのindexedDBがあるにもかかわらず、プレフィックス付きのwebkitIndexedDBも実装しています。
関連情報
- Using IndexedDB
- Starting transactions:
IDBDatabase
- Using transactions:
IDBTransaction
- Setting a range of keys:
IDBKeyRange
- Retrieving and making changes to your data:
IDBObjectStore
- Using cursors:
IDBCursor
- Reference example: To-do Notifications (view example live.)