Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:27:10+00:00 2026-06-05T16:27:10+00:00

I can’t figure out what’s wrong with this snippet of code. I have an

  • 0

I can’t figure out what’s wrong with this snippet of code. I have an indexedDB instance. The keyPath is auto-generated. I can successfully add objects to the DB and get all objects in the DB, but I can’t successfully search for an object in an index I created.

See my jsfiddle: http://jsfiddle.net/R5ngM/13/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:27:13+00:00Added an answer on June 5, 2026 at 4:27 pm

    Haven’t nailed it perfectly yet but the issue seems to be that you’re opening the cursor on your object store, rather than the index. With the default keyPath that works fine but it won’t work when you’re trying to use a secondary index.

    What I think you’re looking to do should look like:

        var request = null;
        if ( null === index || 'undefined' === typeof index ) {
            request = transaction.openCursor( keyRange );
        } else {
            request = index.openCursor( keyRange );
        }
        request.onsuccess = on_success;
    

    UPDATE: I spent a lot of time looking in the wrong place after finding the above issue with the index cursor. Here’s the issue: The object you’re storing is an array not an object literal.

    I was looking into the object you were storing and noticed this:

            var entry = '<li>'+row[0].fname+' '+row[0].lname+'</li>';
    

    See how you’re accessing the first element of the row array? You’re storing an array. Your keypath (and me) assumed an object was stored. I believe it’s possible to have an index on an array but in any case your keyPath is off.

    Here’s a largely-similar chunk of working code. I mucked it up a bit while debugging but you’ll get the gist. (It’s a nice snippit so if you don’t mind, I’ll use it as the base of other StackOverflow examples later on.)

    Keep the cursor on the index as explained in my answer above. Then change to this line:

    var entry = '<li>'+row[0].fname+' '+row[0].lname+'</li>';
    

    And the change this:

    var newUser = [{fname:$('#fname').val(),lname:$('#lname').val()}];
    

    To this:

    var newUser = {fname:$('#fname').val(),lname:$('#lname').val()};
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can't seem to figure out what's wrong with the simple getJSON call below. It's
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can anyone help me trying to find out why this doesn't work. The brushes
Can I order my users in the database, so I don't have to say
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
Can anyone explain to me why this program: for(float i = -1; i <
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.