[GIS] how to disable duplicate items in the legend for ArcGIS JavaScript API

arcgis-javascript-apiarcgis-serverjavascriptlegend

I have a problem with duplicate items in the legend panel!

Legend

Can anyone help me?
This is my feature Layer with popup info:

// Feature Layer
        var msFeatureLayer = new esri.layers.FeatureLayer("url",{
            mode: esri.layers.FeatureLayer.MODE_SELECTION,
            outFields: ["*"],
            infoTemplate:new esri.InfoTemplate({
                title:"<b>infos</b>",
                content:"<b>Code:</b>${Code}<br/>"  
            }),
            displayOnPan:true,
            visible:true,
            opacity:1.0
        });

And here i adding the layer to the map and to the legend:

legendLayers.push({layer:msFeatureLayer,title:'Ms'});
        map.addLayers([msFeatureLayer]);

        // control when add a Layer to the map
        dojo.connect(map,'onLayersAddResult',function(results){
            // Activate all Features from a Feature Layer
            showFromFeatureLayer(msFeatureLayer,"1=1");


            // Legend init
            new esri.dijit.Legend({
                map:map,
                layerInfos:legendLayers
            },"legendDiv").startup();

            // Add Checkboxes with label
            dojo.forEach(legendLayers, function(layer){         
                var checkBox = new dijit.form.CheckBox({
                    name: "checkBox" + layer.layer.id,
                    value: layer.layer.id,
                    checked: layer.layer.visible,
                    onChange: function(evt) {
            var clayer = map.getLayer(this.value);clayer.setVisibility(!clayer.visible);                            this.checked = clayer.visible;
                    }
                });
                dojo.place(checkBox.domNode,dojo.byId("toggle"),"after");
                dojo.place("<br />",dojo.create('label',{'for':checkBox.name, innerHTML:layer.title},checkBox.domNode,"after"),"after");
            });
        });

Best Answer

You may try inspecting the object that has your list of items and building a new one containing the single instance of the strings in the old object. This sounds like what you might be trying to do. If not, then please let me know and i will refine the approach, as appose to simply down voting me ;). The idea is to filter your object with duplicates by constructing a new one with only one copy of what you want to see in it. I hope that helps.