I've already read the documentation:
https://dojotoolkit.org/reference-guide/1.10/dojo/domReady.html
and also a related question:
Dojo timing issue with dijit/registry and dojo/domReady
Still I'm unsure about the correct approach. Like the other user, I have a (quite long) single page web-application with several views.
All my js requires dojo/domReady! but it isn't enough to guarantee the correct behavior of dijit/registry at loading.
This is my configuration:
script(type="text/javascript").
dojoConfig = {
has: {
"dojo-firebug": false,
"dojo-debug-messages": false,
isDebug: false
},
parseOnLoad: false,
mblHideAddressBar: true,
async: true
};
script(src="/javascripts/dojo/dojo.js")
script(type="text/javascript").
require([
"dojox/mobile/parser",
"dojox/mobile/View",
"dojox/mobile/Button",
"dojox/mobile/TextBox",
"dojox/mobile/RoundRect",
"dojox/mobile/FilteredListMixin",
"dojox/mobile/TextArea",
"dojox/mobile/Switch",
"dojox/mobile/FormLayout",
"dojox/mobile/SimpleDialog",
"dojo/domReady!"
], function (parser) {
parser.parse();
});
Then, for each view, I have a js function like this template:
#viewLogin(data-dojo-type="dojox/mobile/View" data-dojo-props="selected:true")
...
script(type="text/javascript").
require([
"dojo/dom",
"dojo/on",
"dojo/request/xhr",
"dojo/dom-form",
"dojo/_base/window",
"dijit/registry",
"dojox/mobile/parser",
"dojox/mobile/View",
"dojox/mobile/compat",
"dojox/mobile/Button",
"dojox/mobile/TextBox",
"dojox/mobile/RoundRect",
"dojox/mobile/FormLayout",
"dojox/mobile/SimpleDialog",
"dojo/domReady!"
], function (dom, on, xhr, domForm, win, registry) {
var txt = registry.byId("txtName").set("value", userName);
...
It's enough to wrap into a ready(function(){ }); all the code inside each js script?
Actually the question might be splitted in two:
- could it work?
- is it the recommended way?