Dojo.Connect with click event for div element insi

2019-09-11 15:21发布

I'm trying to show alert message including click event on div element that are sought through a loop. The problem is that in any div I click, it is only displayed the alert of the last element. How can I solve? I do not understand the logic being performed.

                for (var i = 0; i < this.legend.layerInfos.length; i++)
                {   
                    var sNomeDiv = "";
                    var sMensagem = ""; 

                    if (this.legend.layerInfos[i].layer.visible)
                    {
                        sNomeDiv = this.legend.id + "_" + this.legend.layerInfos[i].layer.id;                                               

                        if (this.legend.layerInfos[i].layer.description == "" || this.legend.layerInfos[i].layer.description == "undefined" || this.legend.layerInfos[i].layer.description == "null")
                        {
                            sMensagem = "Nenhuma informação cadastrada para a camada " + this.legend.layerInfos[i].title;
                        }
                        else
                        {
                            sMensagem = this.legend.layerInfos[i].layer.description;
                        }


                        //Always display an alert with the text of the last element of the loop
                        dojo.connect
                        (
                            dojo.byId(sNomeDiv), 
                            "onclick", 
                            function()
                            {      
                                alert(sMensagem + " --> " + sNomeDiv);
                            }
                        );
                    }
                }

0条回答
登录 后发表回答