Search code examples
javascriptjqueryodatasapui5

How to destroy global model in SAPUI5


I'm trying to destroy global model but with no luck. I have button for filter which looks like this:

navToSecond : function (oEvent){
        var oObject = this.getView().byId("inp").getValue();
        sap.ui.getCore().setModel(oObject, "Filters");
        this.getRouter().navTo("second"); 
        },

In the second view I have smart table with filtered oData after I fill input fields in first view. Then I press button to navigate back on the first page and I want to refresh or destroy global model and read input from fields again. Then it should send new request URL.

I was trying like this:

sap.ui.getCore().getModel("Filters").destroy();

or

sap.ui.getCore().getModel("Filters").refresh(true);

Solution

  • if you want use destroy and refresh function,you must confirm sap.ui.getCore().getModel("Filters") result object have this two function.
    I guessed you can try this:

    sap.ui.getCore().setModel(null, "Filters");
    

    or:

    sap.ui.getCore().setModel("", "Filters");