Reputation: 157
I want to create an index when i store data using indexeddb. But I have a structure json like like this:
{"query":
{"page":
{"4558":
{"pageid":4558,"title":"my-title","revisions": [{"user":"dake","timestamp":"54778788585","comment":"#REDIRECT[[Wikipedia:Welcome]]"}]}}}}
I just want to create a index which can stores only the value of "title".How can in do?
ObjetStore.createIndex("title","title",{unique:false}) seem does not work.
The number "4558" is dynamic,it's not the same on each record.This tructure is provided by the Wikipedia API that i use to create a webapp. Thank a lot and sorry for my english
Upvotes: 0
Views: 771
Reputation: 11448
What you ask for specically is impossible to do in IndexedDB. IndexedDB does support key paths but they consist of one or more fixed identifiers. E.g. query.page.title
or something would work, but there's no way to allow an arbitrary number to appear inside this path.
You can best convert this data to something more sensible (i.e. something resembling a database record, at the top-level) beforehand. Since IndexedDB supports deep key paths, the id and title of these pages do not have to appear at the top-level of these objects per se, but if your in control of the data, it's good practice to make it so.
Maybe it's enough if you essentially remove the {"query": {"page": {"4558":
part of the structure. Beyond that, the data looks pretty much ok.
Upvotes: 0