我不能从同一个控制器的另一个函数调用一个函数.我在控制器中有什么:
checkData: function(){
if(//check the data here before submitting it to the server){
//display error message if the data is not ok
}
else{
//call the function that submits data - submitData
}
},
submitData: function(){
//make ajax call here
}
Run Code Online (Sandbox Code Playgroud)
如何从checkData函数else块中调用submitData函数?
以下是上述两个函数的完整代码: 链接到JSBin
你只需要使用"this"符号.像这样:
checkData: function(){
if(//check the data here before submitting it to the server){
//display error message if the data is not ok
}
else{
//call the function that submits data - submitData
this.submitData();
}
},
submitData: function(){
//make ajax call here
}
Run Code Online (Sandbox Code Playgroud)
如果在事件函数内调用 checkData函数,则"this"表示触发事件而不是控制器的组件.在这种情况下,您可以使用以下语法调用submitData函数:
var oController = sap.ui.getCore().byId("your-view-name").getController();
oController.submitData();
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
19513 次 |
| 最近记录: |