如何在 SAPUI5 中重新加载组件?

How to reload a component in SAPUI5?

我有一个 SAPUI5 应用程序,它使用 sap.ui.core.ComponentContainer 在自身内部加载其他应用程序。类似于 fiori launchpad 的东西。但令人惊讶的是,当我从页面中删除组件容器并稍后尝试重新加载它时,它会被添加到 HTML 页面但不会显示。

var oPage = this.getView().byId("page");
    oPage.removeAllContent();
    if(!this._aComps[sObjectId]){
        this._aComps[sObjectId] = new sap.ui.core.ComponentContainer({ name: sObjectName});
    }
    oPage.addContent(this._aComps[sObjectId]);

知道它只在初始化时显示的原因是什么吗?

虽然此代码始终有效:

var oPage = this.getView().byId("page");
    oPage.removeContent();
    oPage.addContent(new sap.ui.core.ComponentContainer({ name: sObjectName}));

经过大量调查,我似乎在 SAPUI5 中发现了一个错误。

删除 ComponentContainer 并再次添加后发生的事情是 SAPUI5 从组件容器元素中删除 style="height: 100%;"

似乎在再次添加后 return 高度没有恢复到默认值。我还测试了 setVisible 功能,问题也存在于那里。

那么我们要做的是:

var oPage = this.getView().byId("page");
    oPage.removeAllContent();
    if(!this._aComps[sObjectId]){
        this._aComps[sObjectId] = new sap.ui.core.ComponentContainer({ name: sObjectName});
    }
    oPage.addContent(this._aComps[sObjectId]);
    this._aComps[sObjectId].setHeight("100%"); // Set the height to 100% again!

注意: 它不仅为组件容器本身而且为其他一些父元素删除了 height: 100%;。请专心看图!虽然这个解决方案对我有用,但在其他用例中可能需要设置其他一些元素的高度!