Skip to Content
avatar image
Former Member

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Feb 22, 2017 at 10:45 PM

    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();
           }
    

    }); });

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 22, 2017 at 09:28 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 22, 2017 at 09:34 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 22, 2017 at 11:16 PM

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

    Add comment
    10|10000 characters needed characters exceeded