0
votes

I have a controller and a view class.In my controller class I have this code. I am trying to get the AccNo which is passed in the url. I know this code works fine for retrieving the account number, but I now need to pass the Var in to the view class.

    getURLParameter : function(name) {
        return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
    },

    // Parse URL parameters 
    parseAndSetURLParameters : function(){

        var accNo    = this.getURLParameter('accNo');

    },
1
What do you mean by pass the Var in to the view class?Ashish Patil
Sorry I was a bit unclear, so the var accNo is in the class headercontent.controller. I want to display it in heandercontent.view class.J0rd4n500
Which is the UI5 control you are using to display value?Ashish Patil

1 Answers

0
votes

First of all you might want to have a look at jQuery.sap.getUriParameters.

To make variables available to a view the easiest and most convenient way is to use a JSONModel like this:

parseAndSetURLParameters: function() {
  var oModel = new sap.ui.model.json.JSONModel({
    accNo: jQuery.sap.getUriParameters().get("accNo");
  });
  this.getView().setModel(oModel, "view");
}

and in your XMLView:

<Text text="{view>/accNo}" />

Or even more generically you could just pump all uri-parameters in a JSONModel and set it right on your Component (be aware that I use internal api ('mParams') here):

new sap.ui.model.json.JSONModel(jQuery.sap.getUriParameters().mParams);

BR Chris