Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does dijit/registry's byId() method "not exist"?

Tags:

dojo

I'm trying to use digit/registry to get the object for a digit so I can read/change its proprerties. But for some reason I get a JavaScript error that no "byId" method exists for the registry object in the (trimmed-down) code below:

define(["dojo/dom-style", "dijit/registry", [...] ],
        function(domStyle, registry, [...])
{
    var self =
    {
        moveSplitter: function(datasetsLength)
        {   
             var myBC = registry.byId("studiesBorderContainer");    
        },
    }
}

I seem to be able to duplicate this problem in JSFiddle:

http://jsfiddle.net/rUNNr/2/

Yet it works on the Dojo documentation page (see the example at the very bottom of the page... compare first line of output when you click Run with that on the JSFiddle.)

What am I missing? (Note: it's also possible I didn't set up the JSFiddle correctly for a dojo example.)

like image 554
Vern Jensen Avatar asked Jan 25 '26 19:01

Vern Jensen


2 Answers

It appears (at least in the Fiddle you linked to), that you are never actually creating the dijit by calling parser.parse().

I added the call to parser.parse as the first line in your ready callback, and got back a valid dijit Id from registry.byId().

like image 137
Lucas Avatar answered Jan 28 '26 23:01

Lucas


The registry.byId() documentation provides insight into this:

... it only works on parsed dijits either declared in markup with a data-dojo-type attribute or programmatically. The same id attribute is used as a parameter, but what is returned in this case is an object that was created by the dojo widget system when the markup is parsed and transformed into a dijit.

So in your example, this behavior makes sense:

  • The first case is that the div with ID "textNode3" is not an actual Dojo widget, and so it would not recognized by Dojo's registry module.
  • The second case is that while you're provided a data-dojo-type attribute to the input of ID "myTextBox3", Dojo still hasn't actually parsed any of the markup yet. You'll notice in the last example on the reference guide for registry that they call to the parser module to actually interpret the markup provided.

Adding this line to your Fiddle made the example work as intended.

like image 45
pseudoramble Avatar answered Jan 28 '26 22:01

pseudoramble



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!