admin管理员组文章数量:1396139
I am trying to get the input value, but when I call the function I get the error this.getView() is not a function
Below is the function in 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" : ""
}
);
}
And here is the input in the view
<m:Input id="multiInput" value="teste" placeholder="Clique no botão ao lado para buscar o usuário" showValueHelp="true" valueHelpRequest="valueHelpRequest" width="auto"/>
I am trying to get the input value, but when I call the function I get the error this.getView() is not a function
Below is the function in 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" : ""
}
);
}
And here is the input in the view
<m:Input id="multiInput" value="teste" placeholder="Clique no botão ao lado para buscar o usuário" showValueHelp="true" valueHelpRequest="valueHelpRequest" width="auto"/>
Share
Improve this question
asked May 3, 2017 at 14:44
Rubens CesarRubens Cesar
292 gold badges3 silver badges10 bronze badges
1 Answer
Reset to default 3I would assume that you get that error on the second this.getView()
from inside the callback. You are getting this because of the way that this
works in JavaScript. See the following MDN documentation: https://developer.mozilla/en/docs/Web/JavaScript/Reference/Operators/this.
In a nutshell, calling a function freely without it being referenced from "inside" an object (i.e. fnFunction()
vs oObject.func()
), will cause the this
to point to either nothing or the window object. To get the right this
, you can either use the arrow function declaration, the jQuery.proxy method or the .bind function:
onClose: oAction => {
// your code
}
// OR
onClose: function(oAction) {
// your code
}.bind(this)
// OR
onClose: jQuery.proxy(function(oAction) {
// your code
}, this)
本文标签: javascriptSAPUI5thisgetView() is not a functionStack Overflow
版权声明:本文标题:javascript - SAPUI5 - this.getView() is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744645058a2617351.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论