Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create index on array element in indexeddb #11

Open
a2prn opened this issue Jan 4, 2014 · 5 comments
Open

How to create index on array element in indexeddb #11

a2prn opened this issue Jan 4, 2014 · 5 comments

Comments

@a2prn
Copy link

a2prn commented Jan 4, 2014

I have an object.

var _data = {
teacher : {
name : "Mack",
subject : "Maths"
},
Student : [{
stud_name : "Alex",
stud_id : 1
},{
stud_name : "Jack",
stud_id : 2
},{
stud_name : "Mark",
stud_id : 3
}]
};

I want to create index on array element of object.
i.e, I want to create an index on stud_name. Is it possible to create such type of index in indexeddb?

@webcss
Copy link
Owner

webcss commented Jan 4, 2014

Please refer to indexeddb documentation https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB to learn how to create indexes (on array elements).

@a2prn
Copy link
Author

a2prn commented Jan 11, 2014

Thanks webcss, I am able to create index on array element if I have object like this,

var data = {
teacher : {
name : "Mack",
subject : "Maths"
},
Student : ["Mark" , "John"]
}

by using:
store.createIndex("indexname","data .Student", {unique:false,multiEntry:true});

But I am not able to create index on array of object element.

eg:
var data = {
teacher : {
name : "Mack",
subject : "Maths"
},
Student : [{
studname : "Alex",
stud_id : 1
},{
stud_name : "Jack",
stud_id : 2
},{
stud_name : "Mark",
stud_id : 3
}]
};

In object above data object has Student array, which has multiple objects. And I want to create index on array of object (data.Student.stud_name). Is it possible to create such type of index?

@webcss
Copy link
Owner

webcss commented Mar 4, 2014

As proposed here https://developer.mozilla.org/en-US/docs/IndexedDB/Using_IndexedDB#Structuring_the_database it definitly is possible to solve your problem.

@webcss webcss closed this as completed Mar 4, 2014
@webcss webcss reopened this Mar 4, 2014
@fredtma
Copy link

fredtma commented Jan 14, 2016

Has there been a solution to this?
The specified link does not say much

@codershop
Copy link

It currently is not possible to create an index from a property of an object in an array of objects. There was an issue filed for the spec that you can follow here: w3c/IndexedDB#35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants