SAPUI5 指出多種VIEW類型,包括XML,HTML,JavaScript
推薦使用XML,因為可讀性更高
我們提前介紹一下MVC架構。
MVC是一種軟件架構模式,它包括三個主要組件:模型(Model)、視圖(View)和控制器(Controller)。這三個組件分別負責處理應用程序的數據、用戶界面和用戶輸入。MVC的設計目的是將應用程序的邏輯和用戶界面分離,以實現代碼的重用、可維護性和可擴展性。該模式通常用于開發Web應用程序和桌面應用程序。
上一個章節,我們是使用了一個標準text控件去輸出一句hello word
那么為了符合MVC架構,我們在這個章節,我們將輸出的這部分內容,放在VIEW.XML中
webapp/view/App.view.xml
<mvc:Viewxmlns="sap.m"xmlns:mvc="sap.ui.core.mvc"><Text text="Hello World"/>
</mvc:View>
新建完成之后,我們需要去修改index.js 去告訴程序,在哪里加載view
webapp/index.js
sap.ui.define(["sap/ui/core/mvc/XMLView"
], (XMLView) => {"use strict";XMLView.create({viewName: "ui5.walkthrough.view.App"}).then((oView) => oView.placeAt("content"));
});
一些注意點:
Conventions
-
View names are capitalized
-
All views are stored in the?
view
?folder -
Names of XML views always end with?
*.view.xml
-
The default XML namespace is?
sap.m
-
Other XML namespaces use the last part of the SAP namespace as alias (for example,?
mvc
?for?sap.ui.core.mvc
)
這個章節的輸出內容與上章節一致,只是實現方法不同,逐漸格式化