如何在视图控制器中动态更改 UI5 中的标准应用程序标签文本 [英] How to change Standard Application label text in UI5 dynamically in view controller

查看:50
本文介绍了如何在视图控制器中动态更改 UI5 中的标准应用程序标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在扩展来自 ODATA 的 SAP 标准 HCM 应用程序和标准字段 (STRAS) 标签是房屋编号和街道",但我想在运行时在 UI5 视图控制器中更改和分配新标签文本地址行 1"而不是复制标准 ODATA 并为这个小改动创建自定义 ODATA.

i am extending SAP standard HCM Application and standard field(STRAS) label coming from ODATA is 'House Number and Street' but i want to change and assign new label text 'Address Line 1' in UI5 View controller at runtime instead of copying standard ODATA and creating custom ODATA for this small change.

注意:标签在标准应用中没有通过 i18n 模型绑定

Note : Label is not bound through i18n Model in standard Application

<!-- Street / STRAS -->
<Label text="{/#Address10/Street/@sap:label}" id="lblStreet" labelFor="txtStreet" visible="{FieldStates>/STRAS/Visible}"/>
<Text id="txtStreet" text="{Street}" visible="{FieldStates>/STRAS/Visible}"/>

任何帮助将不胜感激.

问候,

推荐答案

你可以尝试实现一个控制器扩展.

您只需要在 "sap.ui5" 对象内的 manifest.json 文件中添加以下代码:

You just need to add the following code in your manifest.json file inside the "sap.ui5" object:

"extends": {
    "component": "Standard App Namespace",
    "extensions": {  
        "sap.ui.controllerExtensions": {
            "standard.namespace.controller.ControllerName": {
                "controllerName": "my.namespace.ControllerNameExt"
            }
        }
    }
}

只需将命名空间替换为适合您用例的命名空间即可.

Just replace the namespaces with the correct ones for your use case.

在控制器实现中,您可以添加(检查页面以了解有关创建控制器的详细信息):

In the controller implementation you can add (check is page for details on creating the controller):

onInit: function() { 
   this.getView().byId("lblStreet").setText("my new label"); 
}

这篇关于如何在视图控制器中动态更改 UI5 中的标准应用程序标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆