0

我试图制作一个函数来将外部视图 htmlpages 加载到视图中,然后执行转换。但是,当我的函数加载时,它会在我的页面外打开 2 个视图,其中只有一个标题为“我的应用程序”的标题和一个以“主页”为标题的后退按钮。我没有收到任何错误,但我没有做它必须做的事情。

这是我的功能。

    goTo : function(viewId){
        WL.Logger.debug("goTo function START");


        var home= "mainView";
        require(["dojo/dom",  "dijit/registry" , "dojo/on", "dojox/mobile/View","dojo/domReady!"], 
                function(dom, registry, on, view){

        var currentView = registry.byId(home).getShowingView();
        var view = registry.byId(viewId);

        WL.Logger.debug("viewId =" + viewId + ", currentViewId=" + currentView.id);

        if(currentView.id != viewId){
            var url = "views/klappr/"+viewId+".html";
            // view.destroyDescendants();

            dojo.xhrGet({
                url: url,
                handleAs: "text",
                load: function(response, ioArgs){
                    view.innerHTML = response;
                    //parser.parse(view);
                    currentView.performTransition(viewId, 1, "slide"); 
                }
            });


            //dijit.registry.byId(viewId).transitionTo({ url: url, transition: "slide", transitionDir: 1, urlTarget:viewId });
        }
        });
    }

这些是创建的视图。(不必创建)

    <div class="mblView" id="dojox_mobile_IconContainer_0_mblApplView"         widgetid="dojox_mobile_IconContainer_0_mblApplView" style="visibility: visible;"><h1 class="mblHeading mblHeadingCenterTitle" id="dojox_mobile_Heading_1" widgetid="dojox_mobile_Heading_1" style="-webkit-user-select: none;"><span role="button" class="mblToolBarButton mblToolBarButtonHasLeftArrow" tabindex="0" id="dojox_mobile_ToolBarButton_0" dir="ltr" widgetid="dojox_mobile_ToolBarButton_0"><span class="mblToolBarButtonArrow mblToolBarButtonLeftArrow mblColorDefault mblColorDefault45"></span><span class="mblToolBarButtonBody mblColorDefault"><table cellpadding="0" cellspacing="0" border="0" class="mblToolBarButtonText"><tbody><tr><td class="mblToolBarButtonIcon"></td><td class="mblToolBarButtonLabel">Home</td></tr></tbody></table></span></span><span class="mblHeadingSpanTitle" style="">My Application</span><div class="mblHeadingDivTitle" role="heading" aria-level="1">My Application</div></h1><div class="mblContainer" id="dojox_mobile_Container_0" widgetid="dojox_mobile_Container_0"><div class="mblIconItemPane" id="dojox_mobile__IconItemPane_0" widgetid="dojox_mobile__IconItemPane_0" style="display: none;"><h2 class="mblIconItemPaneHeading"><div class="mblIconItemPaneIcon" role="" title="" tabindex="0"><div title="" class="mblDomButtonBlueMinus mblDomButton"><div><div></div></div></div></div><span class="mblIconItemPaneTitle">Klas 1A</span></h2><div class="mblContent"></div></div><div class="mblIconItemPane" id="dojox_mobile__IconItemPane_1" widgetid="dojox_mobile__IconItemPane_1" style="display: none;"><h2 class="mblIconItemPaneHeading"><div class="mblIconItemPaneIcon" role="" title="" tabindex="0"><div title="" class="mblDomButtonBlueMinus mblDomButton"><div><div></div></div></div></div><span class="mblIconItemPaneTitle"></span></h2><div class="mblContent"></div></div></div></div>
    <div class="mblView" id="dojox_mobile_IconContainer_1_mblApplView" widgetid="dojox_mobile_IconContainer_1_mblApplView" style="visibility: visible; display: none;"><h1 class="mblHeading mblHeadingCenterTitle" id="dojox_mobile_Heading_2" widgetid="dojox_mobile_Heading_2" style="-webkit-user-select: none;"><span role="button" class="mblToolBarButton mblToolBarButtonHasLeftArrow" tabindex="0" id="dojox_mobile_ToolBarButton_1" dir="ltr" widgetid="dojox_mobile_ToolBarButton_1"><span class="mblToolBarButtonArrow mblToolBarButtonLeftArrow mblColorDefault mblColorDefault45"></span><span class="mblToolBarButtonBody mblColorDefault"><table cellpadding="0" cellspacing="0" border="0" class="mblToolBarButtonText"><tbody><tr><td class="mblToolBarButtonIcon"></td><td class="mblToolBarButtonLabel">Home</td></tr></tbody></table></span></span><span class="mblHeadingSpanTitle" style="">My Application</span><div class="mblHeadingDivTitle" role="heading" aria-level="1">My Application</div></h1><div class="mblContainer" id="dojox_mobile_Container_1" widgetid="dojox_mobile_Container_1"><div class="mblIconItemPane" id="dojox_mobile__IconItemPane_2" widgetid="dojox_mobile__IconItemPane_2" style="display: none;"><h2 class="mblIconItemPaneHeading"><div class="mblIconItemPaneIcon" role="" title="" tabindex="0"><div title="" class="mblDomButtonBlueMinus mblDomButton"><div><div></div></div></div></div><span class="mblIconItemPaneTitle">Klas 1A</span></h2><div class="mblContent"></div></div><div class="mblIconItemPane" id="dojox_mobile__IconItemPane_3" widgetid="dojox_mobile__IconItemPane_3" style="display: none;"><h2 class="mblIconItemPaneHeading"><div class="mblIconItemPaneIcon" role="" title="" tabindex="0"><div title="" class="mblDomButtonBlueMinus mblDomButton"><div><div></div></div></div></div><span class="mblIconItemPaneTitle"></span></h2><div class="mblContent"></div></div></div></div>
4

1 回答 1

0
  • 使用您的代码的相关部分(不按原样运行),我使用 Dojo 1.9.0 和 1.8.3 成功测试了它,即 load() 函数按预期调用。
  • 您是否检查了控制台以防它显示异常?您是否检查了执行流程是否到达直到调用 dojo.xhrGet?(如果你不能断点,使用 alert() 调用)。您是否检查过“url”变量是否指向实际存在的文件?
  • 以防万一,您是否需要 dojo/_base/xhr 模块,这是必需的,因此定义了 dojo.xhrGet ?
  • 您没有提及您的 Worklight 或 Dojo 版本(它们总是有用的信息)。你能告诉dojo.version的内容吗?
  • 从 Dojo 1.8 开始,dojox.xhrGet 被弃用,取而代之的是 dojo/request/xhr(参见 https://dojotoolkit.org/reference-guide/1.8/dojo/xhrGet.html)。您指出的 Dojo Mobile 文档确实缺少更新;该文档将被修复。但是,如上所述,已弃用的 API 在我的测试中确实有效,我只是提及它以供您参考。
  • 最后,一个建议:如果您使用的是 WL 6.0+(因此,Dojo 1.9+),您可以考虑使用 dojox.app(参见https://dojotoolkit.org/documentation/tutorials/1.9/dojox_app/上的教程)。
于 2013-08-14T13:44:14.623 回答