在上一个教程中,已经增加了一个对话框,这一节在对话框上增加用户交互功能。——增加一个“ok”。
webapp/controller/HelloPanel.controller.js里增加函数:
事件处理程序函数放入同一控制器文件中,并通过访问返回对话框的内部帮助程序函数来关闭对话框。
(后面将不再引用所有代码了。)
,
onCloseDialog : function () {
// note: We don't need to chain to the pDialog promise, since this event-handler
// is only called from within the loaded dialog itself.
this.byId("helloDialog").close();
}
webapp/view/HelloDialog.fragment.xml
在片段定义中,我们向对话框的 beginButton 聚合添加一个按钮。事件处理程序是指名为 .onCloseDialog 的事件处理程序。通过使用 loadFragment 函数创建片段内容,按下按钮时将在此处调用该方法。该对话框具有一个名为 beginButton 和 endButton 的聚合。在这两个聚合中放置按钮可确保将 beginButton 放置在 UI 上的 endButton 之前。然而,之前的意思取决于当前语言的文本方向。因此,我们使用术语开始和结束作为“左”和“右”的同义词。在具有从左到右方向的语言中,beginButton 将呈现为左侧,结束按钮呈现在对话框页脚的右侧;在特定语言的从右到左模式下,顺序会切换。
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core" >
<Dialog
id="helloDialog"
title ="Hello {/recipient/name}">
<beginButton>
<Button
text="{i18n>dialogCloseButtonText}"
press=".onCloseDialog"/>
</beginButton>
</Dialog>
</core:FragmentDefinition>
webapp/i18n/i18n.properties
# App Descriptor
appTitle=Hello World
appDescription=A simple walkthrough app that explains the most important concepts of SAPUI5
# Hello Panel
showHelloButtonText=Say Hello
helloMsg=Hello {0}
homePageTitle=Walkthrough
helloPanelTitle=Hello World
openDialogButtonText=Say Hello With Dialog
dialogCloseButtonText=Ok
结果:可以看到增加了“ok",点击后对话框关闭。