Question

I have a dojox.mobile site that has a common view. I would like to reuse the view for multiple "buttons" and call a function which changes the label of the view's heading depending on which button was pushed. However, when I change the innerHTML, the back button disappears. When I use the setattr function, the label doesn't change. What is the proper way to handle this?

</link> --> Demo This Problem

    <div id="MainMenu" data-dojo-type="dojox.mobile.View" data-dojo-props="selected: true" style="width: 100%; height: 100%;">
        <h1 data-dojo-type="dojox.mobile.Heading">View A</h1>

        <h2 dojoType="dojox.mobile.RoundRectCategory">Select a View</h2>
        <ul data-dojo-type="dojox.mobile.RoundRectList">
            <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props="rightText:'Go!', moveTo: 'generic_view_x', callback:SetupViewA">
                View A
            </li>
            <li data-dojo-type="dojox.mobile.ListItem" data-dojo-props="rightText:'Go!', moveTo: 'generic_view_x', callback:SetupViewB">
                View B
            </li>
        </ul>
    </div>

    <div id="generic_view_x" data-dojo-type="dojox.mobile.View" style="width: 100%; height: 100%;">
        <h1 id="view_x_header" data-dojo-type="dojox.mobile.Heading" data-dojo-props="back:'Main', moveTo:'MainMenu',label:'test'"></h1>

            <div id="map_canvas"  style="width: 100%; height: 100%;">
                Some Other Stuff Here
            </div>


    </div>



    <!-- configure and load dojo -->
    <script src="./dojo/dojo.js" data-dojo-config="async:1, mblAlwaysHideAddressBar:true"></script>

    <script>

        require(["dojo"], function(dojo){

        SetupViewA = function (){
            // Doing it This way removes the back button
            // document.getElementById('view_x_header').innerHTML = 'View A';
            // This doesn't change anything
            dojo.setAttr("view_x_header", 'label','View A')

        }
        SetupViewB = function (){

                document.getElementById('view_x_header').innerHTML = 'View B';

        }


                })

        require(["dojox/mobile/parser", "dojox/mobile", "dojox/mobile/deviceTheme", "dojox/mobile/compat", "dojo/domReady!"],
                function(parser) {
                parser.parse();
                });


    </script>

</body>

Was it helpful?

Solution

With widgets, like the header, its best to use its get/set to change attributes of the widget.

you should use:

 dijit.registry.byId("view_x_header").set("label", "View B");

Fiddle::http://jsfiddle.net/theinnkeeper/Wgx8u/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top