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

最后输出的效果如下

相关推荐
修电脑的猫8 小时前
Performance Monitoring on Production Systems in SAP ERP(ABAP性能优化)
性能优化·abap
LilySesy4 天前
ABAP+&SFSY-FORMPAGES&变成星号
经验分享·sap·abap·erp系统·smartforms
一只团子(Lucas Chu)15 天前
跟着团子学SAP PS:SAP项目型制造方案补充方案-SAP PMMO简介
sap·ps·eppm
小哥来啦24 天前
SAP 生产订单报工检查报错异常(接口)
sap·co11n·co13
SAP-nkGavin1 个月前
ABAP设计模式之---“童子军法则(The Boy Scout Rule)”
设计模式·sap·abap
SAP-nkGavin1 个月前
简单说一说Modern ABAP这个概念
sap·abap
爱喝水的鱼丶1 个月前
SAP-ABAP:在DEBUG过程中修改内表中的数据的方法详解
运维·开发语言·sap·异常处理·abap·修改内表
爱喝水的鱼丶2 个月前
SAP-ABAP:ABAP异常处理与SAP现代技术融合—— 面向云原生、微服务与低代码场景的创新实践
开发语言·低代码·微服务·云原生·sap·abap
爱喝水的鱼丶2 个月前
SAP-ABAP:SAP的BAPI_PO_CHANGE功能详解
开发语言·sap·abap·bapi·采购订单修改
IT小白农民工2 个月前
SAP Business One(B1)打开自定义对象报错【Failed to initialize document numbering:】
经验分享·sap