Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to define dojo module for reference by onClick in HTML?
    primarykey
    data
    text
    <p>I'm trying to follow the latest Dojo1.9 best AMD practices when defining a separate javascript module to be referenced by the JSP markup. I used to have a large javascript section in the same JSP file, MyJayEsspEe.jsp, where the javascript section defined functions that were called by various element onClick properties. Now I am separating the javascript into a new file called MyCallbacks.js using the Dojo define mechanism.</p> <p>The format of the MyCallbacks.js looks like:</p> <pre><code>define(["dojo/dom", "dojo/dom-style", "dojo/has", "dijit/registry", "dojo/on"], function (dom, domStyle, dojoHas, registry, on) { ... function clickedOnButton1() { console.log("Clicked on button1"); } function clickedOnLinkTwo() { console.log("Clicked on second link"); } ... return { clickedOnButton1: clickedOnButton1, clickedOnLinkTwo: clickedOnLinkTwo } }); </code></pre> <p>and in the MyJayEsspEe.jsp file I currently have working ugly markup that includes:</p> <pre><code>... &lt;button data-dojo-type="dijit/form/Button" type="button" onclick="require(['commonjs/MyCallbacks'], function(mycallbacks) {mycallbacks.clickedOnButton1();});"&gt;First Button&lt;/button&gt; &lt;a id="testLinkId" href="#" onclick="require(['commonjs/MyCallbacks'], function(mycallbacks) {mycallbacks.clickedOnLinkTwo();});"&gt;Link Two&lt;/a&gt; ... </code></pre> <p>but I'm hoping there's a way to define the module and require it such that in the markup I could have cleaner callbacks like so:</p> <pre><code>... &lt;button data-dojo-type="dijit/form/Button" type="button" onclick="mycallbacks.clickedOnButton1();"&gt;First Button&lt;/button&gt; &lt;a id="testLinkId" href="#" onclick="mycallbacks.clickedOnLinkTwo();"&gt;Link Two&lt;/a&gt; ... </code></pre> <p>I've been reviewing the Dojo reference documentation for defining modules and callbacks but so far haven't found a pointer to the clean solution that I'm looking for. Is there a cleaner solution than the one I've been using?</p> <p>Thanks for your time, Gregor</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload