0

I created a Icon menu on my first swap view with multiple IconMenuItems. This is a snipet of the code. How do I manipulate the individual IconMenutItems from the JS file? I tried both retrievals of the first IconMenutItem resulting in the retrieval of a [object HTMLLIElement] instead of the IconMenuItem. Even with a call to the button.label or button.title it came back as undefined. Is it possible to manipulate a specific dojo item after it is created? Sorry if this is a beginner question, I am very new to both Worklight and Dojo

HTML:

    <div data-dojo-type="dojox.mobile.SwapView"id="MainPageView"
    data-dojo-props="selected:true">
        <ul data-dojo-type="dojox.mobile.IconMenu" id="menu"
        style="width: 320px; height: 400px;" data-dojo-props="cols: 3">
            <li data-dojo-type="dojox.mobile.IconMenuItem"label="empty"
            onclick=handleButton(this) id="btn1" title="title1"></li>
        </ul>
    </div>

JS:

    var button1= document.getElementById("btn1");
    WL.Logger.debug(""+button1.label);

    var button2= dojo.query("#btn1");
    WL.Logger.debug(""+button2.label);*

1 Answer 1

1

Use the dijit/registry

require(['dijit/registry'], function(registry) {
    var btn1 = registry.byId("btn1");
});

Here's a fiddle: http://jsfiddle.net/cswing/GyzXG/

http://dojotoolkit.org/reference-guide/1.9/dijit/registry.html

6
  • I am getting the same results as the other two retrievals. btn1 is a HTMLLIElement and its label is undefined. How would I go about manipulating the label on the original IconMenuItem's label?
    – JSchif11
    Commented Jul 10, 2013 at 14:44
  • Are you sure that the html is being parsed by the parser? Commented Jul 10, 2013 at 15:10
  • Yeah, I included the line "<script type="text/javascript" src="dojo/dojo.js" data-dojo-config="parseOnLoad: true"></script>" within the html head
    – JSchif11
    Commented Jul 10, 2013 at 15:15
  • Does registry.toArray() contain any widgets? My guess is that there is an error on parsing. Does your mobile browser have a console that will show javascript errors? Commented Jul 10, 2013 at 15:23
  • Yeah it contains all the widgets that I created within the html file. The mobile browser's console is not showing any javascript errors when I run the code. When I debug the code within the require statement that you gave me it works great! Does this mean that any changes to the widgets need to be done within the require statement?
    – JSchif11
    Commented Jul 10, 2013 at 15:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.