xml - SAP UI5 XML 视图中的控制语句 if-else
问题描述
我对 UI5 技术有疑问。
在 XML View 中我们如何使用控制语句?例如像 if-else。我有一个条件,如果满足,应该呈现一些不同的代码行。我查了一下,我可以找到预处理器指令:
代码:
<template:if test="{meta>ImageUrl}">
<template:then>
<Image src="{path: 'meta>ImageUrl', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
</template:then>
<template:else>
<Text text="{path: 'meta>Title/Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
</template:else>
</template:if>
但是,“模板”的命名空间 (xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1") 不再存在。
有谁知道如何让这个工作?我不想使用三元运算符,这对于这种情况是不可行的。
解决方案
您可以使用可见属性。然后控件将被渲染但不显示。格式化程序使条件无论是undefined还是null都更易于阅读。
XML:
<Image visible="{ path: 'meta>ImageUrl', formatter: '.Formatter.visible' }" src="{path: 'meta>ImageUrl', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
<Text visible="{ path: 'meta>ImageUrl', formatter: '.Formatter.visible' }" text="{path: 'meta>Title/Value', formatter: 'sap.ui.model.odata.AnnotationHelper.format'}" />
格式化程序:
visible : function(value) {
return !(typeof(value) === 'undefined' || value === null);
}
推荐阅读
- r - 通过变量值控制 ggplot 线宽
- intellij-idea - 如何在 Mac 上关闭单个 JetBrains IDE?
- firebase - Firebase 存储和 Cloud Firestore/实时数据库有什么区别?
- python - python:如何将json转换为数据框
- python - 用 Python 保存数据帧字典的最佳文件格式是什么?
- ssl - 谷歌云平台静态网站 SLL 问题
- ruby-on-rails - 设计验证用户名的存在
- scala - 在 Scala 中将日期字符串转换为日期
- java - Junit 在 Bean 初始化之前创建测试数据模式
- spring-boot - Liquibase 不填充更改日志表中的上下文列