get method

Retrieves a record from an object store.

Syntax

object.get(key, retVal)

Parameters

key [in]

Type: any

The key value of the record to be retrieved.

Exceptions

This method can throw the following DOMException exceptions:

Note  As of a Windows Store app using JavaScript, the code property is deprecated in favor of the name property, which is preferred for standards compliance and future compatibility.

Exception propertiesCondition
name: DataError

The key parameter value is not valid.

name: InvalidStateError
code: DOMException.INVALID_STATE_ERR (11)

The object store has been deleted or is otherwise not available.

name: TransactionInactiveError

The associated transaction is not active.

Standards information

Examples

This example uses the get method to locate an object store record using the value of an index, rather than the key value. For more info, see Managing data with transactions.


     var aStoreNames = [ "ImageDetails", "ImageTags" ];
     var hTransaction = hDBHandle.transaction( aStoreNames, "readonly" );
     var hDetails = hTransaction.objectStore( "ImageDetails" );
     var hIdxImage = hDetails.index( "IxImagesByName" );
     var hImageReq = hIdxImage.get( sFilename );
     hImageReq.onsuccess = function( evt ) {

        var oDetails = evt.target.result;
        if ( oDetails == null ) {
       
          // No details were found for the image, so create
          // defaults to show to the user.
          oDetails = { "ImageTitle" : "<Untitled Image>",
                       "ImageDesc" : "<No description>" };
         }
         updateFormData( oDetails );
    }
   };


See also

IDBIndex
IDBObjectStore

 

 

Show:
© 2014 Microsoft