SAPUI5:如何从同一控制器中的另一个函数调用函数

kes*_*het 0 sapui5

我不能从同一个控制器的另一个函数调用一个函数.我在控制器中有什么:

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

mjd*_*mjd 8

你只需要使用"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)

希望这可以帮助.