SAPUI5 - this.getView() 不是函数

SAPUI5 - this.getView() is not a function

我正在尝试获取输入值,但是当我调用该函数时出现错误 this.getView() is not a function

下面是controller中的函数

    handleConfirmationMessageBoxPress: function(oEvent) {
        var bCompact = !!this.getView().$().closest(".sapUiSizeCompact").length;
        MessageBox.confirm(
            "Deseja confirmar a transferência?", {
                   icon: sap.m.MessageBox.Icon.SUCCESS,
                   title: "Confirmar",
                    actions: [sap.m.MessageBox.Action.OK, sap.m.MessageBox.Action.CANCEL],
                    onClose: function(oAction) {
                      if (oAction == "OK"){
                          var loginA = this.getView().byId("multiInput").getValue();
                          alert(loginA)
                          MessageToast.show("Transferência efetuada");

                      }else{
                         // MessageToast.show("Transferência não cancelada");
                           }

                        },
                        styleClass: bCompact? "sapUiSizeCompact" : ""
            }
        );
    }

这是视图中的输入

   <m:Input id="multiInput" value="teste" placeholder="Clique no botão ao lado para buscar o usuário" showValueHelp="true" valueHelpRequest="valueHelpRequest" width="auto"/>

我假设您在回调中的第二个 this.getView() 收到了该错误。你得到这个是因为 this 在 JavaScript 中的工作方式。请参阅以下 MDN 文档:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/this.

简而言之,在没有从 "inside" 对象引用的情况下自由调用函数(即 fnFunction()oObject.func()),将导致 this 指向什么都没有或 window 对象。要获得正确的 this,您可以使用 arrow function declaration, the jQuery.proxy method or the .bind 函数:

onClose: oAction => {
   // your code
}

// OR

onClose: function(oAction) {
   // your code
}.bind(this)

// OR

onClose: jQuery.proxy(function(oAction) {
   // your code
}, this)