I am using jQuery Dynatree checkboxes to filter markers by date in a Google Map here: http://crocdoc.ifas.ufl.edu/projects/chameleonmapdev/
The checkboxes for specific dates work just fine, but I am having trouble figuring out how to best make the month checkboxes show/hide all the appropriate markers. I was hoping for some sort of onChange event that I could attach to the date checkboxes (since they do get checked/unchecked if the parent checkbox does), but I can't seem to find anything like that in the documentation ( http://wwwendt.de/tech/dynatree/doc/dynatree-doc.html#h5.1 ) so I am using the onSelect function, though this will not automatically target dates if a parent month is selected. I would like to get an array of the keys of all children if a folder is checked/unchecked. So far, I can retrieve the object describing all children, but I'm not sure how to parse it since the keys are in objects inside that object.
onSelect: function(select, node) {
console.log('isFolder: '+node.data.isFolder);
if (node.data.isFolder === true) {
console.log(node.data.children);
//Parse node.data.children to get array of child keys
} else {
if (select === false) {
for (g in marker_container[node.data.key]) {
marker_container[node.data.key][g].setMap(null);
}
}
if (select === true ) {
for (g in marker_container[node.data.key]) {
marker_container[node.data.key][g].setMap(map);
}
}
}
}
node.data.children
returns:
[Object { title="July 12, 2011", select=true, key="July1211"}, Object { title="July 14, 2011", select=true, key="July1411"}, Object { title="July 26, 2011", select=true, key="July2611"}, Object { title="July 27, 2011", select=true, key="July2711"}, Object { title="July 28, 2011", select=true, key="July2811"}]
Any hints are greatly appreciated. And I am very open to any suggestions on how to improve this code in general.
Parsing isn't quite the right term here. What you see in the log is a string describing the object, but there's no need to parse it. The brackets [
and ]
, enclosing the comma separated objects, indicate that node.data.children
is an array containing the child objects. Each object has a property named 'key', which you can get by iterating over the array like this:
if (node.data.isFolder === true) {
var keys = [];
for (var i = 0; i<node.data.children.length; i++){
keys[i] = node.data.children[i].key;
}
}