Note that there are some explanatory texts on larger screens.

plurals
  1. PODojo AMD: Can't call a function inside a require
    primarykey
    data
    text
    <p>I am really a newbie to dojo but as i started developing a new application with dojo version 1.7.2 i also wanted to use the new AMD syntax for functions. Unfortunately i don't seem to get it. :-( </p> <p>What annoys me most is that i can't simply call any function which is inside of a "require"-block. For example i have a page which on opening creates a dynamic table with several widgets in each row. Then i have a button which adds one empty row each time pressed.</p> <p>Without AMD syntax it would be easy:<br> - put all my "dojo.require()" in the HEAD<br> - and then create a bunch of my own functions for creating the table and widgets<br> - the add row function could easily access any global-variables my previous function filled </p> <p>But with AMD its like this: </p> <p>Initial function creates the table and widgets: </p> <pre><code>function fillReportTable(repId) { require(["dojo/dom-construct", "dojo/dom-attr", "dijit/form/FilteringSelect", "dojo/data/ItemFileReadStore", "dijit/form/ComboBox", "dijit/form/DateTextBox", "dijit/form/Select", "dojo/store/Memory"], function (domConstruct, domAttr, FilteringSelect, ItemFileReadStore, ComboBox, DateTextBox, Select, Memory) { // a lot of code to create the table, consisting of SEVERAL functions function createNewRow(tbl) { ...} function function1 () {... } function function2 () {... } function function3 () {... } } </code></pre> <p>Now the "Add Empty Row" button calls its own function "addEmptyRow".<br> But in this function I have to:<br> - do an other require for each dojo-module again<br> - I CAN'T use any of the functions which are "inside" of the "fillReportTable"-function. For example the "createNewRow"-function </p> <pre><code> function addEmptyRow() { require(["dojo/dom-construct", "dojo/dom-attr", "dijit/form/FilteringSelect", "dojo/data/ItemFileReadStore", "dijit/form/ComboBox", "dijit/form/DateTextBox", "dijit/form/Select", "dojo/store/Memory"], function (domConstruct, domAttr, FilteringSelect, ItemFileReadStore, ComboBox, DateTextBox, Select, Memory) { // a lot of code to create the table, consisting of SEVERAL functions } </code></pre> <p>This all seems to be so much complicated with AMD.<br> Or am i missing something obvious here ?<br> With AMD if you separate your code into a lot of small functions, do you do the "require" inside EACH function all over again ? Or do you put all the functions inside one "require" with the full list ?<br> If you do it the second way, how can you call these functions from widget events? </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