简体   繁体   中英

How to refresh(reload) SAPUI5 oModel (oData)

I have a following problem. I am able to properly call function UserDelete to delete a row with user data in table on SAP side but deleted object is still in oModel. How to refresh or destroy and recreate oModel ? I tried to use :

oModel.destroy();
var oModel = new sap.ui.model.odata.ODataModel("http://plaut0001.plaut.pl:8000/sap/opu/odata/sap/ZUSERINFO_SRV/",true,"developer","gliwice");   
sap.ui.getCore().setModel(oModel);

but after this i got following error: Uncaught TypeError: Cannot read property 'dataServices' of undefined

below is the code I use to call function deleting user on SAP side:

//handle delete button
handleDelete : function(evt) {
    var context = evt.getSource().getBindingContext();
    var oModel = sap.ui.getCore().getModel();
    oModel.callFunction('UserDelete', 'POST', 
            {Userid : context.getProperty("Userid")}, 
            null, 
            function(){sap.m.MessageBox.show("Pomyślnie usunięto");}, 
            function(){sap.m.MessageBox.show("Błąd");}
        );


    sap.ui.getCore().getEventBus().publish("nav", "to", {
        viewId : "app.details.Empty",
        data : "" 
    });

You have to bind the service after the remove command in your code. Please provide sample Jsbin link that you have already tried.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM