Legend with Visible Layers - how to modify for sublayers?

Discussion created by acwalker on Jul 12, 2012
Latest reply on Apr 29, 2014 by norcalheidi
I'm using this tutorial to create a map with legend and checkboxes for turning layers on and off.  Currently it only gives one checkbox per map service if you are using a Dynamic Map Service (which I am because I need labels and Feature Layers do not support labels).

How can I modify this code so it gives a checkbox for every sublayer in the Dynamic Map Service instead of just one checkbox that turns everything on/off?