M.Mikuš
M.Mikuš

Reputation: 51

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);

Upvotes: 0

Views: 4772

Answers (3)

Ruud Raijmakers
Ruud Raijmakers

Reputation: 1

enter image description here

Once a model has been destroyed from sap.ui.getCore() there's a flag indicating that the model has been destroyed.

Upvotes: 0

Markus Bauernschmitt
Markus Bauernschmitt

Reputation: 181

The question of this thread is "How to destroy global model in SAPUI5"

Ying Yi answered it correctly. If you unset the model, all references to the model will be deleted and the garbage collector can do his job.

But your real problem is to fire the executing of the query to update your table. Destroy and recreate models is the wrong way. Work with events how I descriped it in your other thread to this subject.

Upvotes: 1

Ying Yi
Ying Yi

Reputation: 782

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");

Upvotes: 1

Related Questions