IDBKeyRange.lowerBound()

IDBKeyRange 接口的lowerBound()方法创建一个只有下限的新的键范围。默认情况下,它包含较低的端点值。

Note: 此特性在 Web Worker 中可用。

Syntax

var myIDBKeyRange = IDBKeyRange.lowerBound(lower);
var myIDBKeyRange = IDBKeyRange.lowerBound(lower, open);

Parameters

lower 
指定新键范围的下限。
open 可选
指示下限是否排除端点值。默认值为false。

Return value

IDBKeyRange: 新创建的键范围.

Exceptions

此方法可能引发以下类型的 DOMException :

Exception Description
DataError

The value parameter passed was not a valid key.

Example

下面的示例演示如何使用下限键范围。在这里,我们声明keyRangeValue = IDBKeyRange.lowerBound("F", false);— 一个包含值“F”及其后所有内容的范围。我们打开一个事务(使用 IDBTransaction)和一个对象存储,并使用 IDBObjectStore.openCursor打开一个游标,声明keyRangeValue 为其可选的键范围值。这意味着光标将只检索键值为“F”及其后面的所有记录。如果使用IDBKeyRange.lowerBound("F", true);,则该范围将不包括端点“F”,仅包括其后面的值。

Note: 要获得一个更完整的示例,使您能够使用键范围进行实验,请查看我们的 IDBKeyRange-example实时查看该示例)。

function displayData() {
  var keyRangeValue = IDBKeyRange.lowerBound("F");

  var transaction = db.transaction(['fThings'], 'readonly');
  var objectStore = transaction.objectStore('fThings');

  objectStore.openCursor(keyRangeValue).onsuccess = function(event) {
    var cursor = event.target.result;
      if(cursor) {
        var listItem = document.createElement('li');
        listItem.innerHTML = '<strong>' + cursor.value.fThing + '</strong>, ' + cursor.value.fRating;
        list.appendChild(listItem);  
          
        cursor.continue();
      } else {
        console.log('Entries all displayed.');
      }
    };
  };

Specification

Specification Status Comment
Indexed Database API 2.0
lowerBound()
Recommendation
Indexed Database API Draft
lowerBound()
Recommendation

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
lowerBoundChrome Full support 24
Full support 24
No support 23 — 24
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 12Firefox Full support 16
Full support 16
No support 10 — 16
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Full support 10
Notes
Full support 10
Notes
Notes partial
Opera Full support 15Safari Full support 7WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 22Opera Android Full support 14Safari iOS Full support 8Samsung Internet Android Full support Yes

Legend

Full support  
Full support
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

See also