Skip to Content
0

How to call controller function from an event press a button on a dialog in the same controller?

Feb 22, 2017 at 09:15 PM

82

avatar image
Former Member

Create the getModelView method to get the view model,

getModelView: function () {

return this.getView (). getModel (). getJSON ();

},

But when I want to call it from a button in the endButton property of sap.m.Dialog throws me the following message in console. Uncaught ReferenceError: getModelView is not defined How could access the function from the press event of the button that is inside the dialog? Thanks in advance

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Srikanth KV Feb 22, 2017 at 10:45 PM
0

Hi,

In the event handler of the button 'this' refers to current scope of the method. So you cannot access the model directly.

Approach would be to store controller reference in a variable and access it

sap.ui.define([
	"sap/ui/core/UIComponent",
	"sap/ui/model/json/JSONModel",
	"sap/ui/demo/wt/controller/HelloDialog"
], function (UIComponent, JSONModel, HelloDialog) {
      "use strict";

      var _oController;      //variable used to store controller reference
	
      return UIComponent.extend("sap.ui.demo.wt.Component", {

        init: function () {
            _oController = this; //reference of controller 
       },

       getModelView: function(){
           return _oController.getView().getModel().getJSON();
       }

}); });

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member
Feb 22, 2017 at 09:28 PM
0

How are you calling getModelView() from the XML view?

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Feb 22, 2017 at 09:34 PM
0

I do not call getModelView from the view, if not from the controller

onCreate: function(){

...

var oData = this.getModelView();

...

},

But I think this refers to the button

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Feb 22, 2017 at 11:16 PM
0

thanks for the reply. you were right. But now I have another problem friend, no funciona el binding data.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

can you show the error screenshot and code..

0