Reputation: 1831
From testing it turns out the boolean returned by the OData V4 service was translated to strings 'No' and 'Yes' somewhere between the READ and the binding. I have no idea what can be causing this.
OData loaded by $batch request to load suggestion items:
{
"@odata.context": "$metadata#SkillVocabularyItems",
"value": [
{
"randomId": "622d4068-9928-4446-931a-45b443356dae",
"skill": "MongoDB",
"trending": true
},
{
"randomId": "d9ed304a-c1bc-454c-b4db-970f87ee3943",
"skill": "MongoLab",
"trending": false
}
]
}
XML binding that I expect to work
<SearchField
id="searchField"
busy="{view>/loadingSkillSuggestions}"
placeholder="Search for a skill..."
enableSuggestions="true"
suggest=".onSuggestSkills"
suggestionItems="{/SkillVocabularyItems}"
>
<suggestionItems>
<SuggestionItem
icon="{= ${trending}? 'sap-icon://trend-up' : '' }"
text="{skill}"
description="{trending}"
key="{skill}"
/>
</suggestionItems>
</SearchField>
XML binding that works, showing the value in the model is litterally 'No' or 'Yes'. This 'No' or 'Yes' is also visible in the 'description' of the SuggestionItems.
<SearchField
id="searchField"
busy="{view>/loadingSkillSuggestions}"
placeholder="Search for a skill..."
enableSuggestions="true"
suggest=".onSuggestSkills"
suggestionItems="{/SkillVocabularyItems}"
>
<suggestionItems>
<SuggestionItem
icon="{= ${trending}? 'sap-icon://trend-up' : '' }"
text="{skill}"
description="{trending}"
key="{skill}"
/>
</suggestionItems>
</SearchField>
Upvotes: 1
Views: 891
Reputation: 1831
Found the documentation where this behavior is described.
By default, a property binding delivers a value formatted according to the target type of the control property it applies to...
Source: Type Determination
The solution is to use %
for the binding expression instead of $
:
The embedded binding
${binding}
delivers a value formatted according to the target type of the control property the expression binding applies to, for example, "boolean" in case of<Icon src="sap-icon://message-warning" visible="{= ${status} === 'critical' }">
. This can be undesirable or even lead to errors, for example, if OData V4 automatically adds the correct type for the "status" property which is string-like, not boolean. In such cases, use the syntax%{binding}
instead.
Source: Expression Binding
Upvotes: 4