SAP UI5 walkthrough step5 Controllers

在这个章节,我们要做的是,将之前的text文本展示为一个按钮,并将声明绑定在点击按钮事件。

因为改的是外观,所以我们修改的是view.XML

webapp/view/App.view.xml

复制代码
<mvc:View
   controllerName="ui5.walkthrough.controller.App"
   xmlns="sap.m"
   xmlns:mvc="sap.ui.core.mvc">
   <Button
      text="Say Hello"
      press=".onShowHello"/>
</mvc:View>

根据MVC架构原理,这种点击按钮事件,应该放在controller里面

所以我们这边要新建一个App.controller.js

webapp/controller/App.controller.js (New)

复制代码
sap.ui.define([
   "sap/ui/core/mvc/Controller"
], (Controller) => {
   "use strict";

   return Controller.extend("ui5.walkthrough.controller.App", {
      onShowHello() {
         // show a native JavaScript alert
         alert("Hello World");
      }
   });
});

Conventions

  • Controller names are capitalized

  • Controllers carry the same name as the related view (if there is a 1:1 relationship)

  • Event handlers are prefixed with on

  • Controller names always end with *.controller.js

最后输出的效果如下

相关推荐
SAP_LO2 天前
STRUST导入证书
证书·sap·trust·imc
snpgroupcn7 天前
能源行业SAP系统升级的技术约束分析:资产数据连续性与切换窗口的工程处理(上篇)
架构·sap
Harrison Ben10 天前
(原创)SAP FI自动入账奥义:FBKP FBKA FBKF
运维·sap·sap fico·sap运维·sap 实施
xiao贱贱10 天前
SAP ABAP OPEN SQL(应用实战大全)
sap·abap·opensql
爱喝水的鱼丶14 天前
SAP-ABAP:ECC→S/4HANA ABAP 迁移升级指南——程序改造、语法兼容与性能优化 导语
运维·开发语言·性能优化·sap·abap·经验交流·开发交流
snpgroupcn15 天前
SAP ECC → S/4HANA 迁移的工程化路径:范围建模、规则复用与短停机窗口切换
sap·sap实施商
yang9822617 天前
S4 CLOUD
sap
爱喝水的鱼丶20 天前
SAP-ABAP:S/4 HANA ABAP 新特性入门:与 ECC ABAP 的核心差异、架构优势与学习路径规划
运维·数据库·性能优化·sap·abap·hana·开发交流
山茶花开时。24 天前
[SAP ABAP] SAP设置定时执行任务Job
sap·sap abap
SAP_LO24 天前
对检验批次做决策后物料状态并没有改变的处理方法
sap·aq11·bs02·检验批