UI5:从自定义控件中调用视图中的函数

时间:2019-03-04 14:57:33

标签: controller sapui5 sap-fiori

这是我的实际情况:

我目前正在使用UI5和MVC原理开发应用程序。出于功能原因,我创建了一个自定义控件。在此自定义控件中,有一个视图函数(除了我正在使用控制器和视图之外)。

现在,这是实际的问题:如何从自定义控件调用函数?

我从控制器调用函数没有问题,但是我无法从自定义控件中调用函数。

详细信息: 在我的“ App.view.xml”中,我已经链接了控制器和自定义控件:

<mvc:View xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="..." xmlns:core="..." xmlns:l="..." xmlns:f="..." xmlns="..." xmlns:customControl="..." controllerName="..." displayBlock="true">

我试图从自定义控件调用函数,如下所示:

<Button xmlns="sap.m" xmlns:customControl="..." text="Description" press="functionfromcustomcontrol"/>

谁能告诉我这段代码有什么问题,或者我应该怎么做才能解决这个问题?

我已经进行了大量研究,但没有找到我想要的东西。 预先感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

XML

<Button xmlns="sap.m" xmlns:customControl="..." text="Description" press="functionfromcustomcontrol"/>

看起来很奇怪。 我假设您定义了一个自己的“按钮”作为从sap.m.Button派生的CustomControl。然后XML应该如下所示:

<customControl:Button text="Description" press="functionfromcustomcontrol"/>

只需看一下openUI5演练Step 34: Custom Controls来获取示例

相关问题