简体   繁体   中英

dojo xhr get load html does not display dojo objects

I'm using dojo 1.9. using xhr.get to load html file which include dojo objects. although the html page display the text, no dojo object was displayed. Coad snipped as follow.

main.js

require(["dojo/_base/xhr", "dojo/dom"], function(xhr,dom){
                var url = require.toUrl("page1.html");
                xhr.get({
                url: url,
                load: function(html){
                    dom.byId("view2").innerHTML = html;

                    var currentView = dijit.registry.byId('view0');
                    currentView.performTransition('#p1view0',1,"slide",null);

                    globalVar = null;
                }
            });
                });

page1.html

<div data-dojo-type="dojox.mobile.View" id="p1view0" data-dojo-props="selected:true">
    <p>
        This is from Page 1
    </p><br>
    <ul data-dojo-type="dojox.mobile.IconMenu" id="menu2"
        style="width: 274px; height: 210px; margin: 20px;"
        data-dojo-props="cols: 1">
        <li data-dojo-type="dojox.mobile.IconMenuItem"
            data-dojo-props="label: 'Go to Home Page',moveTo:'view0'"></li>
    </ul>
</div>

index.html

<!DOCTYPE HTML>
<html>
-----
<body>
-----
<div data-dojo-type="dojox.mobile.ScrollableView" id="view0" data-dojo-props="selected:true">
</div>
<div id="view2">
</div>
<script src="js/main.js"></script>
</body>
</html>

You have to manually call the dojo parser after inserting the new content.
See: http://dojotoolkit.org/reference-guide/1.10/dojo/parser.html

require(["dojo/_base/xhr", "dojo/dom", "dojo/parser"], function(xhr,dom, parser){
            var url = require.toUrl("page1.html");
            xhr.get({
            url: url,
            load: function(html){
                dom.byId("view2").innerHTML = html;

                var currentView = dijit.registry.byId('view0');
                currentView.performTransition('#p1view0',1,"slide",null);

                globalVar = null;

                paerser.parse(dom.byId("view2"));
            }
        });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM