I am trying to filter through the "carObj" below, as a user selects "filters" from a list on a page and display only the "matching" sub-objects.
Currently when a user selects a "filter" it is added to the "filterObj" and then I am rolling through the "carObj" with like 8 $.each statements to pull out all matching sub-objects. I am matching on the values and roll through many times to make it there.
For instance, assuming the example below, only the 3rd Sub-Object in the "carObj" would be "returned" with all of its values. As it stands I am setting an attribute to "TRUE" for all matches and "FALSE" for any that don't.
Then on the webpage I roll through all TRUE valued Sub-Objects in the "carObj" and display their information/Values in a table.
I am not sure any of this is the most efficient way to do it.
/* Object filled as user selects "filters" */
filterObj ={
"Seats": {},
"color": {
"Orange": "Orange",
"Red": "Red"
},
"Transmission": {
"Manual": "Manual"
},
"Make": {
"Ford": "Ford"
},
"Model": {},
"Status": {
"New": "New"
}
}
/* Main object that contains all cars */
carObj = {
"cars": [
{
"seats":"6",
"color":"Red",
"transmission":"Automatic",
"make":"Ford",
"model":"Windstar",
"status":"New",
},
{
"seats":"4",
"color":"Black",
"transmission":"Manual",
"make":"Mazda",
"model":"CRX",
"status":"New",
},
{
"seats":"2",
"color":"Orange",
"transmission":"Manual",
"make":"Ford",
"model":"Galaxy",
"status":"New",
}
]
}