Closed ginestra closed 6 years ago
Solved it creating a different path for the outer and the inner objects and quering them properly:
function results() {
$.each(JSPath.apply(path, data), function(i, supergroup) {
$.each(JSPath.apply(subpath, supergroup), function(j, group) {
$('#results').append('<tr><td>' +
supergroup.year + '</td><td>' +
group.id + '</td><td>' +
group.name + '</td></tr>'
);
});
});
}
Hi, I'm having problems understanding how to retrieve values that match conditions in an inner
$.each()
without returning the whole object.A JSON sample:
If I want to return all name == "bbb" but also have access to the year how would I go about it?
So far I tried nested
$each()
s but it returns the group as an object (as it should) where at least one child matches the condition. The problem is the list will also contain the other child that doesn't.For instance:
JSPath.apply('.supergroup{..name == "bbb"}', data);
will return all names in the groups (id 1, 2, 3, 4).
If I run the query on the group instead:
JSPath.apply('..group{..name == "bbb"}', data);
I get the expected list, but if I try to access the year, I get an undefined error.
My current function to retrieve the results is built like this: