SAP UI5應用裏的列表處理

在XML view裏,使用List標籤引入列表:shell

<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,實如今控制器文件裏:mvc

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]
                }
            );
        }
    });
});

運行效果:點擊列表元素:app

彈出對話框:函數

要獲取更多Jerry的原創文章,請關注公衆號"汪子熙":
ui

相關文章
相關標籤/搜索