cancel
Showing results for 
Search instead for 
Did you mean: 

util.Formatter.js function in JS View

0 Kudos

Hi Expert.

I am trying to complete "Building SAP Fiori-like UIs with SAPUI5" exercise 3 in JS view.

I have problem in calling statusText function of util.Formatter.js in my Detail.view.js.

The original exercise is in xml view.

Below is my codes..

Formatter.js


jQuery.sap.declare("myFioriApp.util.Formatter");

myFioriApp.util.Formatter = {

statusText : function(value) {

var bundle = this.getModel("i18n").getResourceBundle();

return bundle.getText("StatusText" + value, "?")

}

}

Detail.view.js


sap.ui.jsview("myFioriApp.Views.Detail", {

getControllerName : function() {

return "myFioriApp.Views.Detail";

},

createContent : function(oController) {

var oHeader = new sap.m.ObjectHeader({

firstStatus: new sap.m.ObjectStatus(

{text:{

formatter: function(s){

return myFioriApp.util.Formatter.statusText(s)

}}})}

}

Function statusText() did get called but (this.) does not have an instance of text control therefor it fails to call getModel() function of it's aggregate.

Thanks in advance for your reply.

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Currently my workaround is to pass the text's object from the view to Formatter.js but I believe there must be a better answer out there.

Formatter.js


jQuery.sap.declare("myFioriApp.utility.Formatter");

myFioriApp.utility.Formatter = {

statusText: function(textObject,value){

var bundle = textObject.getModel("i18n").getResourceBundle();

return bundle.getText("StatusText" + value, "?")

}}

Detail.view.js


sap.ui.jsview("myFioriApp.Views.Detail", {

getControllerName : function() {

return "myFioriApp.Views.Detail";

}},

createContent : function(oController) {

var oHeader = new sap.m.ObjectHeader({

firstStatus: new sap.m.ObjectStatus({text:

{path: "LifecycleStatus",

formatter: function(s){

return myFoioriApp.utility.Formatter.statusText(this, s)

}

}

})})

}

r_manoj_kumar
Explorer
0 Kudos

Hi Edwin, Please load the dependency. jQuery.sap.require("myFioriApp.util.Formatter");  Thanks, Manoj

0 Kudos

Hi Manoj,

Yes, jQuery.sap.require("myFioriApp.util.Formatter") was in the view controller already.

former_member182862
Active Contributor
0 Kudos

Hi Edwin

{
   text: {
      path: '?',  
      formatter: function(s){  
         return myFioriApp.util.Formatter.statusText(s)  
      }
   }
}  

path is missing

0 Kudos

Hi Dennis,

Thanks for your reply. Yes, the path was there already. I just didn't mention it in my snippet codes. Sorry for confusing .