Object "traversal"
Object "traversal"
It's not really traversal, more like node selector I guess. It might not have anything to do with JQuery but if I can use it to achieve what I want it doesn't matter. I have an object that I create from JSON that looks like:
{
"totalUniversities" : "2",
"universities" : {
"MIT" : {
"key" : "",
"totalPlaces" : "12",
"totalPlacesSpring" : "6",
"totalPlacesAutumn" : "6",
"totalSubjects" : "2",
"subjects" : [
{
"name" : "Agricultural Economics",
"placesSpring" : "3",
"placesAutumn" : "3"
},
{
"name" : "Agricultural Economics",
"placesSpring" : "3",
"placesAutumn" : "3"
}
]
},
"Oxford" : {
"key" : "",
"totalPlaces" : "12",
"totalPlacesSpring" : "6",
"totalPlacesAutumn" : "6",
"totalSubjects" : "2",
"subjects" : [
{
"name" : "Agricultural Economics",
"placesSpring" : "3",
"placesAutumn" : "3"
},
{
"name" : "Agricultural Economics",
"placesSpring" : "3",
"placesAutumn" : "3"
}
]
}
}
}
What I want to do now is to be able to select the "Oxford" university and loop through the subjects (which is easy by doing "myObj.universities.Oxford"). What I want to do is to be able to search for that node with a function, something like:
- getSubjects : function(uniname){
- var uniObj = myObj.universities;
- var myUniObj = uniObj.uniname....
- }
Of course, this won't work unless I put the string together and do an eval on it but there has to be some other way of doing it right? Having a brain fart...
If someone has a better suggestion for my obj structure I'm all ears, it's easy to alter if it would simplify things.