IndexedDB資料庫介紹

jieforest發表於2012-08-12
In order to retrieve data efficiently from an IndexedDB database, each record is organized by its key. The only condition for the key is that it is a valid key. A valid key can be one of the following types:

1. Array (Is only valid when every item inside the array is a valid key and the array doesn’t contains it self. Also all non-numeric properties are ignored and will not affect whether the array is a valid key)

2. DOMString

3. Date (The Primitivevalue (internal property) of the date object can’t be NaN)

4. Float (The key can’t be NaN)

When comparing keys, the order in the list above applies. Array is greater than all DOMStrings, DOMString is greater than …

Comparing arrays is done by comparing the values inside the array (as long that both arrays got values on the position). If the values on the same position differ, then the outcome of that comparison will determine which array is greater. If the values on each position are the same, the length of the array will determine the which one is greater or equal if the arrays have the same length.

Complex Keys

The IndexedDB API also support complex keys. This are keys who refer to properties nested inside an object. This way you are able to filter on data that is available are properties of a nested object. In the example below we have an person object. Besides a name and firstname property it contains an address property. This address property is also an object containing properties like city, street, … If we want to filter data on its city we can do this by defining a key like this “address.city”.
  1. 01.var person = {
  2. 02.name: "name",
  3. 03.firstname: "firstname",
  4. 04.address: {
  5. 05.street: "street",
  6. 06.city: "city"   
  7. 07.}
  8. 08. 
  9. 09.}

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-740808/,如需轉載,請註明出處,否則將追究法律責任。

相關文章