天天看點

SAP UI5應用裡的清單處理

在XML view裡,使用List标簽引入清單:

<mvc:View controllerName="sapcp.cf.tutorial.app.controller.View1" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
    <Shell id="shell">
        <App id="app">
            <pages>
                <Page id="page" title="{i18n>title}">
                    <content>
                        <List items="{/Products}">
                            <StandardListItem type="Active" press="handleListItemPress" title="{ProductName}"/>
                        </List>
                    </content>
                </Page>
            </pages>
        </App>
    </Shell>
</mvc:View>           

上面代碼裡注冊的清單元素點選處理函數handleListItemPress,實作在控制器檔案裡:

sap.ui.define([
    "sap/ui/core/mvc/Controller",
    "sap/m/MessageBox"
], function (Controller, MessageBox) {
    "use strict";

    return Controller.extend("sapcp.cf.tutorial.app.controller.View1", {
        onInit: function () {

        },

        // show in a pop-up which list element was pressed
        handleListItemPress: function (oEvent) {
            MessageBox.show(
                "You pressed item: " + oEvent.getSource().getBindingContext(), {
                    icon: sap.m.MessageBox.Icon.INFORMATION,
                    title: "It works!",
                    actions: [sap.m.MessageBox.Action.OK]
                }
            );
        }
    });
});           

運作效果:點選清單元素:

彈出對話框:

本文來自雲栖社群合作夥伴“汪子熙”,了解相關資訊可以關注微信公衆号"汪子熙"。