passing an argument for click events, AMD style

528
2
Jump to solution
10-31-2013 10:35 AM
TracySchloss
Frequent Contributor
I have a button that used to work fine in my non-AMD syntax.  I have just two layers that I'd like to let the user turn on and off.  I had a small function that would check the current visibility and toggle it on/off depending on its current state.

    //functions for turning layer on/off       function toggleLayer(layerId) {       var layer = app.map.getLayer(layerId);       if (layer.visible) {           layer.hide();        } else {           layer.show();       }     } 


I had the button defined as
<button id="btnWICvendor" dojotype="dijit.form.Button" onClick="toggleLayer('venLayer')"> Click to Hide Sites</button>


From my reading, it sounded like I should be adding the click listener to the button using dojo/on.  Besides updating the button definition, I removed onClick and added this line into my code.  But it doesn't look like I pass any argument with this method. 
registry.byId('btnWICvendor').on('click', toggleLayer);


I thought this would be simple, but apparently not!  What am I missing?  I know I could use TOC, but that seems like overkill for this particular map.
0 Kudos
1 Solution

Accepted Solutions
TracySchloss
Frequent Contributor
I figured it out after a little more reading.  It's hard to do Internet searches on such generic terms (button, click, on ....)

registry.byId('btnWICoffSat').on('click', function (){     toggleLayer('offSatLayer')});

View solution in original post

0 Kudos
2 Replies
TracySchloss
Frequent Contributor
I figured it out after a little more reading.  It's hard to do Internet searches on such generic terms (button, click, on ....)

registry.byId('btnWICoffSat').on('click', function (){     toggleLayer('offSatLayer')});
0 Kudos
NumaGremling
New Contributor
I got clicks to work using Dojo query.
In your case it would look like this:

 require([
  ...
  "dojo/query",
  ...
  ],
  
 function(
  ...

  query, //This is the DOJO query! lower case!   
  ...
  ) {
  
  ...
  
  var vendorButton = query("#btnWICvendor");
  vendorButton.on("click", toggleLayer);
0 Kudos