IDBKeyRange. It is only on composite index in IE

I have the following code:

    this.getChildren = function (db, parentId, foldersOnly, callback, finishedCallback) {
    var transaction = db.transaction("tree", "readonly");
    var objectStore = transaction.objectStore("tree");

    var handleResult = function (event) {
        var cursor = event.target.result;
        if (cursor) {
            callback(cursor.primaryKey, cursor.value);
            cursor.continue();
        } else {
            finishedCallback();
        }
    };

    if (foldersOnly) {
        // Only find records with the correct parentId and IsFolder == 1
        var range = IDBKeyRange.only([parentId, 1]);
        var index = objectStore.index('ParentId IsFolder');
        index.openCursor(range).onsuccess = handleResult;
    } else {
        var range = IDBKeyRange.only(parentId);
        var index = objectStore.index('ParentId');
        index.openCursor(range).onsuccess = handleResult;
    }
};

      

If foldersOnly is false, then it works in all browsers. But if I convey the truth, then it doesn't work in IE. I just get a "Data error" message.

I have also tried

var range = IDBKeyRange.bound([parentId, 1], [parentId, 1]);

      

Does anyone have any suggestions?

Edit:

This is how indexes are created:

 treeObjectStore.createIndex("ParentId", "ParentId", { unique: false });
 treeObjectStore.createIndex("ParentId IsFolder", ['ParentId', 'IsFolder'], { unique: false });

      

+3


source to share


2 answers


IE does not support composite indexes.

Edit:



As a workaround, try creating one property in your objects and create a single index for that property. In your case, try something like "path"? You have to complicate the whole bizlogic add / update, so update this derived field every time, but at least it might work.

For example, as annoying as possible, create a derived string property with a value for each object: ParentId + ':' + (IsFolder? '1': '0').

+4


source


There's a new polyfill for IE that makes it behave like the standard:



https://github.com/dfahlander/idb-iegap

+4


source







All Articles