Calling Controller Function from inside a press ha

2019-06-09 20:10发布

问题:

I want to filter a table on ButtonPress an set the Table + 3 other buttons visible. My wish is to do that in the controller, but I cant seem to find a way to call a Controller Function inside the event Handler.

The Button:

var searchButton = new sap.ui.commons.Button({
            text: 'Partner suchen',
            width: "100%",
            press: function(oEvent) {
                var myInput = sap.ui.getCore().byId('Handler').getValue(); //$('.row input[role="textbox"]:enabled').val();
                var query = oEvent.getParameter("query");

                var listBinding = oTable2.getBinding();
                var oFilter = new sap.ui.model.Filter ("nummer", sap.ui.model.FilterOperator.EQ, myInput);
                listBinding.filter([oFilter]);

                //[oController.enablen, oController]

                //sap.ui.getCore().byId('vertL2').setVisible(true);
                //sap.ui.getCore().byId(this.createId('anlegBut')).setEnabled(true);
                //sap.ui.getCore().byId(this.createId('editBut')).setEnabled(true);
                //sap.ui.getCore().byId(this.createId('submitBut')).setEnabled(true);
            }
        });

In my controller I have this function that I want to call:

enablen : function () {
    var view = this.getView();

    sap.ui.getCore().byId('vertL2').setVisible(true);
    view.byId('anlegBut').setEnabled(true);
    view.byId('editBut').setEnabled(true);
    view.byId('submitBut').setEnabled(true);
}

But calling it inside the Event Handler of the Button seems not possible.

回答1:

The solution to this was (after looking at the API again):

var searchButton = new sap.ui.commons.Button({
            text: 'Partner suchen',
            width: "100%",
            press: /*[oController.enablen, oController]*/ [function(oEvent) {
                var myInput = sap.ui.getCore().byId('Handler').getValue(); //$('.row input[role="textbox"]:enabled').val();
                var query = oEvent.getParameter("query");

                var listBinding = oTable2.getBinding();
                var oFilter = new sap.ui.model.Filter ("nummer", sap.ui.model.FilterOperator.EQ, myInput);
                listBinding.filter([oFilter]);

                this.enablen();

            }, oController]
});