【问题标题】:SAP UI 5 XML-Templating / PreprocessingSAP UI 5 XML-模板/预处理
【发布时间】:2018-05-02 15:19:50
【问题描述】:

我尝试将模板用于我的 XML 视图。

作为一个例子,我有这个:

<mvc:View controllerName="Test_Start.controller.View" 
xmlns:html="http://www.w3.org/1999/xhtml" 
xmlns:mvc="sap.ui.core.mvc" 
xmlns:temp="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
displayBlock="true" xmlns="sap.m">
<App>
    <pages>
        <Page title="{i18n>title}">
            <content>

                <temp:if test="{= ${Data>Enable1} === 'X'}">
                <Text text="Hallo"/>
                </temp:if>
                </content>
        </Page>
    </pages>
</App>
</mvc:View>

我的 Component.js 看起来像这样:

sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device",
"Test_Start/model/models",
"sap/ui/model/odata/v2/ODataModel",
"sap/ui/core/util/XMLPreprocessor"
], function(UIComponent, Device, models, ODataModel, XMLPreprocessor) {
"use strict";

return UIComponent.extend("Test_Start.Component", {

    metadata: {
        manifest: "json"
    },

    /**
     * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
     * @public
     * @override
     */
    init: function() {
        // call the base component's init function
        UIComponent.prototype.init.apply(this, arguments);

        // set the device model
        this.setModel(models.createDeviceModel(), "device");



    },

    onBeforeRendering: function(){
        var oModel = new ODataModel("/sap/opu/odata/SAP/ZPFO_CKPT_ODATA_DYN_SRV/"),
        oMetaModel = oModel.getMetaModel(),
        sPath = "/DataSet";

        oMetaModel.loaded().then(function() {
            var oTemplateView = sap.ui.view({
                preprocessors: {
                    xml: {
                        bindingContexts : {
                            meta : oMetaModel.getMetaContext(sPath)
                        },
                        models: {
                            meta: oMetaModel
                        }
                    }
                },
                type : sap.ui.core.mvc.ViewType.XML,
                viewName: "Test_Start.view.View"
            });
            oTemplateView.setModel(oModel);
            oTemplateView.bindElement(sPath);

        });
    }
});
});

现在,当我尝试运行我的应用程序时,我收到以下错误:

XMLTemplateProcessor-dbg.js:53 未捕获错误:加载失败 'http://schemas/sap/com/sapui5/extension/sap/ui/core/template/1/if.js' 从 ../../resources/http://schemas/sap/com/sapui5/extension/sap/ui/core/template/1/if.js: 404 - 未找到

我做了一些研究,发现我可能在错误的时间加载了预处理器,但我似乎找不到合适的位置来加载它。

我将这个SAPUI5 SDK example 用于我的工作。

  • 编辑

我找到了解决问题的方法:

现在我使用的是“createContent”函数,而不是“onBeforeRendering”函数。我也完全删除了“init”。

除此之外,我还实现了一个 oViewContainer,就像在示例中使用的一样。

【问题讨论】:

  • 我看到至少一个错误 。您定义了名称为“meta”的预处理模型,并在“if”表达式中引用了名称“Data”。应该是
  • @slkorolev ahhh 我明白了,但这并不能解决错误问题
  • 我也有同样的问题,你解决了吗?
  • @DanielFlores 是的,在我的帖子中寻找编辑,有我的解决方案

标签: sapui5


【解决方案1】:

此外,控制器名称“Test_Start.Component”与视图“Test_Start.controller.View”中的控制器名称属性不匹配。

【讨论】:

    猜你喜欢
    • 2016-06-30
    • 2010-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-14
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多