Dojo将内容加载到现有视图中并执行转换会在页面外创建新视图

时间:2013-08-08 09:47:43

标签: dojo ibm-mobilefirst dojox.mobile

我尝试创建一个函数将外部视图htmlpages加载到视图中,然后执行转换。但是当我的函数加载时,它会打开我页面外的2个视图,只有标题为“我的应用程序”的标题和带有“home”标题的后退按钮。我没有错误,但我没有做它必须做的事情。

这是我的功能。

    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>

1 个答案:

答案 0 :(得分: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/上的教程)。