Reputation: 2677
I've defined a new custom module:
status-app/formatter.js
sap.ui.define([], function() {
"use strict";
return {
stringToInt: function(value) {
console.log("Called: " + value);
return parseInt(value);
}
}
});
Then in my controller I defined it as dependency like in Step 23 of the walkthrough and added as controller property.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"status-app/formatter"
], function (Controller, formatter) {
"use strict";
return Controller.extend("stibam-status.Main", {
//formatter: formatter,
formatter: {
stringToInt: function(value) {
console.log(value);
return "";
}
},
[...]
});
I've tried both variants of the code but the formatter is not called. I printed in my onInit-function this.formatter
but it was set correctly. Why is my view not calling my formatter only if I use a anonymous function in the view itself?
Not working
oColListItem.addCell((new sap.m.Text()).bindText({
path: "statusData>AnzPdf",
formatter: ".formatter.stringToInt"
}));
Working
oColListItem.addCell((new sap.m.Text()).bindText({
path: "statusData>AnzPdf",
formatter: function(value) {
console.log(value);
return parseInt(value);
}
}));
Upvotes: 2
Views: 9078
Reputation: 3
i solved this issue with this code.
return Controller.extend("convanl.ConvAnualDesemp.controller.View1", {
formatter: formatter,
----------------------------
var oTemplate = new sap.m.ColumnListItem({
cells: [
new sap.m.Text().bindText({
path: "Rut",
formatter: that.formatter.entregaRutFormateado}),
new sap.m.Text({
text: "{DescEstado}"
})]});
Upvotes: 0
Reputation: 3948
The bindinginfo you provide to the bindText()
method expects a function for its property formatter
. It should look like this:
When inside the Controller
:
oColListItem.addCell((new sap.m.Text()).bindText({
path: "statusData>AnzPdf",
formatter: this.formatter.stringToInt
}));
When inside a JSView
:
createContent: function(oController){
//...
oColListItem.addCell((new sap.m.Text()).bindText({
path: "statusData>AnzPdf",
formatter: oController.formatter.stringToInt
}));
//...
}
The walkthrough you referenced uses XMLViews. In a XMLView the binding info is parsed from the attribute value (a plain string) by the XMLTemplateProcessor. It resolves values like ".formatter" on the Controller
of the View
.
When you're using a JSView
or creating Control
s in your Controller
then you supply the BindingInfo object directly. No string-parsing involved.
Upvotes: 2