javascript - 根据 XML 视图中的条件绑定数据。SAPUI5
问题描述
我已经定义了图标选项卡。我必须根据条件在选项卡的一个字段中显示数据。例如:
对于下面的列,我必须根据条件显示数据。
if text.type ===1,
display text.field1
else if text.type ===2,
.... text.field2
else
.... text.field3
endif.
代码片段:
<ColumnListItem type="Active">
<cells>
<Text text="{= ${/TxtModel/AssignType} === '1' ? }" width="auto" maxLines="2" wrapping="false" textAlign="Center" textDirection="Inherit"/>
</ColumnListItem>
解决方案
利用预处理指令
我正在使用您有 4 个基于AssignType
员工为 1 或 5 或 8 的用例。这里我们正在使用if/then/else
指令。
<template:if test="{= {${aufnrTxtModel>/Ltxt/AssignType} === 1}">
<template:then>
<Text text="{aufnrTxtModel>/Ltxt/Pernr}" width="auto" maxLines="2" wrapping="false" textAlign="Center" textDirection="Inherit"/>
</template:then>
<template:elseif test="{= {${aufnrTxtModel>/Ltxt/AssignType} === 5}">
<Text text="{aufnrTxtModel>/Ltxt/Ingpr}" width="auto" maxLines="2" wrapping="false" textAlign="Center" textDirection="Inherit"/>
</template:elseif>
<template:elseif test="{= {${aufnrTxtModel>/Ltxt/AssignType} === 8}">
<Text text="{aufnrTxtModel>/WCPL}" width="auto" maxLines="2" wrapping="false" textAlign="Center" textDirection="Inherit"/>
</template:elseif>
<template:else>
<Text text="" width="auto" maxLines="2" wrapping="false" textAlign="Center" textDirection="Inherit"/>
</template:else>
</template:if>
您还可以使用自定义格式化程序,您可以在路径中传递AssignType
, Pernr
, Ingpr
,WCPL
这些将在您的formatter
函数中可用,您可以在其中编写所有逻辑,这比这个复杂的 xml 更容易更改。
推荐阅读
- angular - 在 Ionic App 中将导航参数从一个组件传递到应用程序组件时显示错误
- java - com.parse.ParseObject 不能强制转换为
- javascript - 用“role=button”模拟一个 div 元素的点击——JavaScript
- java - Android Google 登录失败 com.google.android.gms.common.api.ApiException: 12500
- javascript - 在tomcat的war文件中编辑js文件
- java - 在复制构造函数中使用直接字段访问而不是 getter 会导致空指针异常
- php - 在 PHP 中打印 mysql 表
- jenkins - 安装 Github 集成插件后 Jenkins 崩溃
- sharepoint-online - 如何在 Sharepoint Online 中设置“社区站点”导航
- arduino - 使用 Arduino IDE 将 Arduino 代码拆分为多个文件