IDBKeyRange: upper プロパティ
        
        
          
                Baseline
                
                  Widely available
                
                
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
メモ: この機能はウェブワーカー内で利用可能です。
upper は IDBKeyRange インターフェイスの読み取り専用プロパティで、キーの範囲の上限を返します。
値
キーの範囲の上限です。(任意の型になり得ます)
例
以下の例では、キーの範囲の使用法を示します。keyRangeValue = IDBKeyRange.upperBound("F", "W", true, true); と定義します。上限と下限の両方が開 (true) として宣言されているので、これは "F" と "W" の間の全ての値を含むが、これらの値は含まない範囲です。(IDBTransaction により) トランザクションを開き、オブジェクトストアを開き、省略可能なキーの範囲の値を keyRangeValue として IDBObjectStore.openCursor でカーソルを開きます。
キーの範囲を宣言した後、その upper プロパティの値をコンソールに記録します。これは "W" になるはずです。
メモ: キーの範囲に関する実験ができるより完全な例は、IDBKeyRange-example リポジトリーを参照してください。(動く例も見る)
js
function displayData() {
  const keyRangeValue = IDBKeyRange.bound("F", "W", true, true);
  console.log(keyRangeValue.upper);
  const transaction = db.transaction(["fThings"], "readonly");
  const objectStore = transaction.objectStore("fThings");
  objectStore.openCursor(keyRangeValue). => {
    const cursor = event.target.result;
    if (cursor) {
      const listItem = document.createElement("li");
      listItem.textContent = `${cursor.value.fThing}, ${cursor.value.fRating}`;
      list.appendChild(listItem);
      cursor.continue();
    } else {
      console.log("全項目を表示しました。");
    }
  };
}
仕様書
| Specification | 
|---|
| Indexed Database API 3.0> # ref-for-dom-idbkeyrange-upper①> | 
ブラウザーの互換性
Loading…
関連情報
- IndexedDB の使用
- トランザクションの開始: IDBDatabase
- トランザクションの使用: IDBTransaction
- キーの範囲の設定: IDBKeyRange
- データの取得と変更: IDBObjectStore
- カーソルの使用: IDBCursor
- リファレンス例: To-do Notifications (動く例を見る)