根据SAPUI5中html元素上的click事件执行功能

时间:2018-07-10 10:43:32

标签: sapui5

嗨,我想让我在控制器中定义的函数在按图片的特定区域时执行。我正在使用html映射来定义图片的区域(下面的代码)

<mvc:View id="Main" controllerName="Demo.picture.controller.Main" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m" xmlns:core="sap.ui.core">
<App id="idAppControl">
    <pages>
        <Page title="{i18n>title}">
            <content>
                    <Image src = "Some image source" alt="Image" useMap="Map"/>
            </content>
        </Page>
    </pages>
</App>
<html:map name="Map" id="Map">
    <html:area id= "area_1" shape="rect" coords= "0,0,240,215" alt="Chart" onclick="???"/>
    <html:area id = "area_2" shape="rect" coords="240,0,480,215" alt="Start" onclick="???"/>
</html:map> </mvc:View>

不确定使用onclick是否是正确的方法。

控制器代码:

sap.ui.define([

"sap/ui/core/mvc/Controller"], function (Controller) {
"use strict";

return Controller.extend("Demo.picture.controller.Main", {


    SomeMethodFoo: function () {
        "method to be executed when area_1 is pressed"
    },

    SomeMethodGoo: function () {
        "method to be executed when area_2 is pressed"
    }

});});

是否可以将onclick事件的eventHandler附加到这些区域?还是有其他方法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

我想可能是这样的:

onclick="sap.ui.getCore().byId('__xmlview0').getController().SomeMethodFoo()"

但是您需要管理自己才能知道自己的视图ID,而该ID并不总是'__xmlview0'

相关问题