axemclion / jquery-indexeddb

An IndexedDB Plugin for Jquery.
Other
195 stars 71 forks source link

createIndex on an array property, each or eachKey with a range argument does not work #49

Open guofengzh opened 10 years ago

guofengzh commented 10 years ago

I modify the demo from https://bitbucket.org/axemclion/indexeddb-cordova-android.git to test how jquery-indexeddb index works on an array property.

I add the categories property ( of array type) to the catalog.json, like the following:

[{
    "itemId": 1001,
    "name": "Desktop",
    "description": "A normal looking desktop computer",
    "price": 100,
    "rating": 2,
    "categories":["x", "y"]

then i create the index on the categories property:

                            "1": function(versionTransaction){
                                var catalog = versionTransaction.createObjectStore("catalog", {
                                    "keyPath": "itemId"
                                });
                                catalog.createIndex("price");
                                catalog.createIndex("name");
                                catalog.createIndex("categories", {
                                          "unique" : false, 
                                          "multiEntry":true
                                       });
                            },

When catalog.json loaded into the db, I use the following to get the catalog items with a specific category:

                            console.log("Transaction completed, all data inserted");
                            loadFromDB("catalog");
                            // **** MY TEST CODE HERE
                            console.log("load by range") ;
                            _($.indexedDB("MyECommerceSite").objectStore("catalog").index('categories').eachKey(function(elem){
                                  console.log("RG:"+JSON.stringify(elem)) ;
                           },['a']));                           

Nothing printed on the console. Only Action complete printed (from the line number on the console, I know that the done() is invoked).

If I remove the range parameter ['a'], the expected result printed, for example:

09-10 13:08:28.346: I/Web Console(24010): RG:{"key":["a","b"],"value":1006} at file:///android_asset/www/index.html:163

What is wrong with my usage of the range parameter?

I run the App on a Android 4.2.2 mobile phone.

Thanks a lot.

Guofeng.