首页 > 解决方案 > 同时显示两次 SAPUI5 查看

问题描述

我构建了一个 sapui5 应用程序,它显示了与 SAP 工厂相关的信息。现在我需要在同一页面上显示相同的视图两次,但要显示两种不同植物的信息。想象一下像两个 iFrame。该应用程序应该能够仅使用一个视图运行(就像现在一样),并且它应该能够在同一页面上多次显示数据。

为了解决这个问题,我构建了一个额外的视图(splitview),其中包含一个组件容器来加载“真实”视图(主视图)。这以一个连续的循环结束。

这就是我尝试构建拆分视图的方式

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:l="sap.ui.layout"
    controllerName="zqinsplotlist.zqinsplotlist.controller.splitview" xmlns:html="http://www.w3.org/1999/xhtml">
    <App>
        <pages>
            <Page title="Title">
                <content>
                    <l:HorizontalLayout class="sapUiContentPadding">
                        <ComponentContainer xmlns="sap.ui.core" name="zqinsplotlist.zqinsplotlist"
                            settings='\{ "componentData" : \{ "startupParameters" : \{"Werks" : ["1001"], "Zfcod" : ["PLOS"], "Herkunft" : ["03"] \} \}\}'/>
                        <Text text="Hello Split"/>
                    </l:HorizontalLayout>
                </content>
            </Page>
        </pages>
    </App>
</mvc:View>

我希望这将加载我的主视图一次。但它会一遍又一遍地循环调用。

标签: sapui5

解决方案


你为什么不试试…… 像这样:

<mvc:View 
  xmlns:core="sap.ui.core" 
  xmlns:mvc="sap.ui.core.mvc" 
  xmlns="sap.m" 
  xmlns:l="sap.ui.layout"
  controllerName="zqinsplotlist.zqinsplotlist.controller.splitview" 
  xmlns:data="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
  xmlns:html="http://www.w3.org/1999/xhtml">
  <App>
    <l:HorizontalLayout class="sapUiContentPadding">
      <mvc:XMLView 
        viewName="zqinsplotlist.zqinsplotlist.view.MyView" 
        data:some="data to distinguish the views" 
        data:instance="1"
      />
      <mvc:XMLView
        viewName="zqinsplotlist.zqinsplotlist.view.MyView" 
        data:some="other data to distinguish this view from the above" 
      />              
    </l:HorizontalLayout>
  </App>
</mvc:View>

在 MyView 的控制器中通过 sth 区分两个视图实例。像这样:

if (this.getView().data('instance') === 1) {
  // do stuff
}

那应该可以,但我还没有测试过。不能 100% 确定自定义数据适用于从 XML 实例化的视图。嗯,应该...

克里斯


推荐阅读