I want to call the function getCountdown
with two parameters:
"Time"
or "Status"
.This is my code:
<ObjectStatus
title="Time"
text="{
parts: [
{path: 'AuctionEnd'},
{path: 'Time'}
],
formatter: '.formatter.getCountdown'
}"
/>
In formatter.js, there is only the first parameter as seen in my console log:
["2016-05-20T12:00:00", undefined]
In JS, I would do it this way:
var AuctionEnd = "2016-05-20T12:00:00";
getCountdown(AuctionEnd, "Time");
As of UI5 1.61 (commit), you can add static values to the binding info object. The syntax is value
instead of path
.
parts: [
{ path: '/modelPath' },
{ value: 123 }
],
Same as with path
, you can enhance the value
binding info with more settings as shown in this demo ==> https://jsbin.com/yeguhow/edit?js,output
As reported on GitHub issue #2916, there is a bug which was fixed first in UI5 1.80.
Consider adding { value: 123, model: <modelName> }
as a temporary solution, or removing the model name from the path
(binding from a default model) to circumvent the issue.
I found another possibility, maybe not completely for the usecase of this question but it was what I was looking for when I found this question.
If the "constant" or "static" text you want to set is an actual translatable text you can define it in the i18n model and then access it like this:
<ObjectStatus
title="Time"
text="{
parts: [
{path: 'AuctionEnd'},
{path: 'i18n>/Time'}
],
formatter: '.formatter.getCountdown'
}"
/>
Maybe a more fitting usecase would be setting the title of a table column and adding an unit from a model to the end like this: "Space [m^2]". Since "Space" has to be translated anyways, you can just pull it from the model directly.
For passing static value to formatter you can use i18n model with no translation (since if you look for property that doesn't exist in i18n.prop it returns the key-word you are looking for):
I was trying to represent 'X, , ,X' as list of check boxes:
// will format the first of values boolvalues.split(',')[index]
selected="{parts: [ 'modelName>/boolvalues', 'i18n>0'], formatter: '.formatter.checkBoxFormatter'}"
In this case I later followed different approach when I realiesd I don't even need formatter:
selected="{= ${modelName>/boolvalues}.split(',')[0] === 'X' }
Solution for version < 1.61:
Register a model to view in init method
onInit: function() { // JSONModel required from "sap/ui/model/json/JSONModel"
var oModelConstants = new JSONModel(Object.freeze({ myConstant: 123 }));
oModelConstants.setDefaultBindingMode("OneTime");
this.getView().setModel(oModelConstants, "constants");
}
In XML view, assign your formatter with the following parts:
<ObjectStatus text="{
parts: [
'AuctionEnd',
'constants>/myConstant'
],
formatter: '.formatter.getCountdownTime'
}" />
For version 1.61 and above, see answer 53609552.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With