在 使用 yo 建立好的 SAP UI5 項目裏,使用命令行:html
yo easy-ui5 project newview:html5
輸入新的視圖名稱爲 Products,建立新的控制器,以及在 manifest.json 裏定義新的 route:web
manifest.json routing 區域裏三個節點增添了新屬性:npm
target 區域增添了新的 id 和 name 同名的Products 視圖,實現類型爲 XML:json
把 pattern 裏字符串內容去掉,變成"":mvc
webapp/view/Mainview.view.xml 是整個應用的外層容器。將 app 標籤頁裏的內容所有刪除:app
建立出來的 Products 頁面的內容爲:webapp
<mvc:View controllerName="tutorial.products.controller.Products" displayBlock="true" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc"> <Page id="Products" title="Available Products"> <content> <List items="{/Products}"> <StandardListItem type="Active" title="{ProductName}" /> </List> </content> </Page> </mvc:View>
使用 aggregation bindings,定義了一個 list.ui
使用命令行 yo easy-ui5 project newmodel 建立一個新模型:url
全部到 data source 的數據請求,都會被髮送到這個 url:
<webapp URL>/V2/Northwind/Northwind.svc/.
Modify the uimodule/webapp/xsapp.json file to redirect the traffic to a destination.
修改 xsapp.json, 將請求從新路由到 destination.
{ "welcomeFile": "/flpSandbox.html", "routes": [ { "source": "^/V2/(.*)$", "authenticationType": "none", "destination": "Northwind", "csrfProtection": false }, { "source": "^(.*)", "target": "$1", "authenticationType": "xsuaa", "service": "html5-apps-repo-rt" } ] }
You already created a destination named Northwind in Cloud Foundry environment of SAP BTP. Now it’s time to add a mocked destination to your local setup as well.
在 uimodule 文件夾下面的 ui5.yaml 文件裏:
定義一個本地 destination:
使用 npm ui5 啓動工程。
最後的效果:
更多Jerry的原創文章,盡在:"汪子熙":