【问题标题】:Set condition in XML table property (SAP UI5)在 XML 表属性中设置条件 (SAP UI5)
【发布时间】:2019-03-15 11:09:45
【问题描述】:

在设置 sap.ui.table 的“rowSettings”聚合时,我想在我的 xml 模板中设置一个条件。

这是我到目前为止的尝试方式(基于我发现的其他问题):

<table:Table id="changedData">
    <table:columns>
        <!-- Columns created in controller -->
    </table:columns>
    <table:rows>
        <!-- Rows created in controller -->
    </table:rows>
    <table:rowSettingsTemplate >
        <table:RowSettings highlight = "{= ${changedModel>highlight} == 'yellow' ? 'Warning' : ${changedModel} == 'green' ? 'Success' : 'None'}"/>
    </table:rowSettingsTemplate>
</table:Table>

这就是我的“changedModel”数据的样子:

因此“highlight”属性应该通知所需的突出显示。

使用上述代码时,即使我检查了 100 次语法,也会出现语法错误。 这就是错误:

预期为 '}' 而在表达式绑定中看到 '=' {= ${changedModel>highlight} == 'yellow' ? '警告' : ${changedModel} == 'green' ? 'Success' : 'None'} 在第 29 位。

我的代码有什么问题?

样本输出 改变数据

(3) [{…}, {…}, {…}]
0:
COL01: "00000000"
COL02: "Sonja"
COL03: "Deißenböck"
COL04: "Studentin"
COL05: "33403215"
COL06: "Hochschule München"
COL07: "Teststraße 2"
COL08: "20160115"
COL09: " 120.00 € "
highlight: "yellow"
__proto__: Object
1:
COL01: "00000001"
COL02: "Leon"
COL03: "Maschine"
COL04: "Student"
COL05: "57945612"
COL06: "TUM"
COL07: "Teststraße 3"
COL08: "20160116"
COL09: " 160.00 € "
highlight: "yellow"
__proto__: Object
2:
COL01: "00000002"
COL02: "Sabine"
COL03: "Betrieb"
COL04: "Studentin"
COL05: "45613789"
COL06: "LMU"
COL07: "Teststraße 4"
COL08: "20160117"
COL09: " 200.00 € "
highlight: "yellow"
__proto__: Object

改变模型

{columns: Array(10), rows: Array(7)}
columns: Array(10)
0: {columnId: "COL01"}
1: {columnId: "COL02"}
2: {columnId: "COL03"}
3: {columnId: "COL04"}
4: {columnId: "COL05"}
5: {columnId: "COL06"}
6: {columnId: "COL07"}
7: {columnId: "COL08"}
8: {columnId: "COL09"}
9: {columnId: "highlight"}
length: 10
__proto__: Array(0)
rows: Array(7)
0: {COL01: "00000000", COL02: "Sonja", COL03: "Deißenböck", COL04: "Studentin", COL05: "33403215", …}
1: {COL01: "00000001", COL02: "Leon", COL03: "Maschine", COL04: "Student", COL05: "57945612", …}
2: {COL01: "00000002", COL02: "Sabine", COL03: "Betrieb", COL04: "Studentin", COL05: "45613789", …}

【问题讨论】:

  • 您是否将 index.html 文件中的 compatVersion 设置为 edge ? data-sap-ui-compatVersion="edge"
  • 哦,我从来没有读过这个!谢谢!现在我在一个“子”项目中工作,我只是从父级继承 index.html 文件,我不想碰它。有没有办法添加它?

标签: javascript xml syntax-error sapui5 conditional-statements


【解决方案1】:

首先确保将 compatVersion 设置为 edge 或将绑定语法设置为复杂,否则将无法使用复杂绑定。

data-sap-ui-compatVersion="edge"
data-sap-ui-xx-bindingSyntax="complex"

关于您的绑定,您在第二个条件中缺少“突出显示”。

<table:RowSettings highlight = "{= ${changedModel>highlight} === 'yellow' ? 'Warning' : ${changedModel>highlight} === 'green' ? 'Success' : 'None'}"/>

【讨论】:

  • 我通过定义脚本标记将 compatVersion 和复杂绑定添加到我的 XML 视图。因此我添加了这个 xmlns:html="w3.org/1999/xhtml" 然后我的脚本标签是这样的:
  • 我完全错过了,您使用的是“==”而不是“===”。如果错误仍然存​​在,请更正并告诉我。
  • 你是对的,这绝对解决了我的错误信息!但由于某种原因它没有被应用。如果我无法访问 index.html 文件,如何正确定义 CompatVersion?
  • 哦,等一下,我刚刚检查了父项目的 index.html 版本,这两个设置实际上已定义..所以它应该可以工作.. :O
  • 它不起作用还是只是应用 highlight = None ?尝试将条件语句的默认值更改为 None 以查看绑定是否正在处理。如果是,则问题出在模型的数据上。如果不是,则表达式绑定不会被解析。
猜你喜欢
  • 1970-01-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-12
  • 2019-05-12
相关资源
最近更新 更多