trbo
trbo

Reputation: 15

using dijit.byId w dojox.mobile widgets

I'm dynamically building a series of dojox.mobile.ListItem widgets under a statically defined dojox.mobile.RoundRectList widget via this function...

function displayOpps(items) {

// Create the list container that will hold application names
var rrlOppsContainer = dijit.byId("rrlOpps");   
// Add a new item to the list container for each element in the server respond
for (var i in items){

    // Create and populate the list container with applications' names
    var name = items[i].CustName + " - " + items[i].OppNbr;
    var liOpps = new dojox.mobile.ListItem({
        label: name,
        moveTo: "sv3OppDetail"  
    });

    // Add the newly created item to the list container
    rrlOppsContainer.addChild(liOpps);
}

}

When I run this code during onLoad() in my html file, I get the following error using Chrome's dev tools...

Uncaught TypeError: Object # has no method 'byId'

I've read numerous articles around this topic and it appears that lots of folks have this problem, but each that I have found are in relation to some other technology (e.g., Spring MVC, etc) and I'm attempting to use it w a dojox.mobile based app. That said, I attempted to mimic some of the solutions brought up by others by including this in my html file, and it still doesn't work...

<script type="text/javascript"
data-dojo-config="isDebug: true, async: true, parseOnLoad: true"
src="dojo/dojo.js">
dojo.require("dojox.mobile.RoundRectList")
</script>

What am I doing wrong?

Thank you in advance for your time and expertise.

Upvotes: 0

Views: 1582

Answers (1)

edurocher
edurocher

Reputation: 316

If you are using Dojo 1.7+, you probably just forgot to require the "dijit/registry" module. This where the byId function is defined. When you use desktop widgets, this is loaded indirectly by other base modules, but with dojox/mobile you must load it explicitly (because dojox/mobile loads only a very minimal set of modules by default, to minimize code footprint).

Depending on how you wrote your application, do this:

dojo.require("dijit.registry");  // legacy (pre-1.7) loader syntax
...
var rrlOppsContainer = dijit.byId("rrlOpps");
...

or this:

require(["dijit/registry", ...], function(registry, ...){ // 1.7+ AMD loader syntax
    ...
    var rrlOppsContainer = registry.byId("rrlOpps");
    ...
});


Note also that your second code sample tries to use asynchronous loading (async: true) while it uses the legacy loader syntax. This won't work, to get async loading you must use the AMD syntax.

Upvotes: 3

Related Questions