在這個章節,我們要做的是,將之前的text文本展示為一個按鈕,并將聲明綁定在點擊按鈕事件。
因為改的是外觀,所以我們修改的是view.XML
webapp/view/App.view.xml
<mvc:ViewcontrollerName="ui5.walkthrough.controller.App"xmlns="sap.m"xmlns:mvc="sap.ui.core.mvc"><Buttontext="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 alertalert("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
?最后輸出的效果如下