I'm currently learning SAP/Open UI5. I have followed some of the tutorials on the openSAP platform. Now I am trying by myself to modify a project (created from the template SAP Fiori Worklist Application). I'm editing the whole project in the Web IDE.
The problem
To come up with the problem I have is, that I have a table with four columns in my XML view. All these columns are filled with data from the OData service.
<ColumnListItem
type="Navigation"
press=".onPress">
<cells>
<ObjectIdentifier
title="{Name}"
text="{ProductID}"/>
<Text text="{SupplierName}"></Text>
<Text text="{= ${WeightMeasure} == 0 ? '-' : ${WeightMeasure}}"></Text>
<ObjectNumber
number="{
path: 'Price',
formatter: '.formatter.numberUnit'
}"
unit="{CurrencyCode}"/>
</cells>
</ColumnListItem>
The code snippet above is in the items
aggregation. When I now start the standalone application, normally the records from the backend appearing. Since I have implemented now the third row with the WeightMeasure expression ({= ${WeightMeasure} == 0 ? '-' : ${WeightMeasure}}
), I receive the following error in the Dev console:
Uncaught (in promise) SyntaxError: Expected '}' and instead saw '=' in expression binding {= ${WeightMeasure} == 0 ? 'Hello' : ${WeightMeasure}} at position 20
at w (BindingParser-dbg.js:445)
at Function.a.complexParser [as bindingParser] (BindingParser-dbg.js:482)
at p (XMLTemplateProcessor-dbg.js:47)
at K (XMLTemplateProcessor-dbg.js:732)
at J (XMLTemplateProcessor-dbg.js:630)
at I (XMLTemplateProcessor-dbg.js:566)
at l1 (XMLTemplateProcessor-dbg.js:862)
The value it self does exist and also show up when I just enter the variable.
What I have tried
Of course, I have checked first the docs and general the internet. I have found the article for expression binding again. But when I have compared the example to my version, it really looks identical. Unless my version does not work.
Also, I have tried it with several relative paths, but with no result in the end. It really looks like there is a syntax error somewhere or what could be the problem?
I recently had this problem too. Try replacing ==
with ===
:
text="{= ${WeightMeasure} === 0 ? '-' : ${WeightMeasure}}"
Or simplified
text="{= ${WeightMeasure} || '-'}"
The issue is that UI5 supports only strict equality operators (===
or !==
) in Expression Binding.