Adam Harkus
Adam Harkus

Reputation: 2210

How do I refresh a view?

I'm refreshing my view model onRouteMatched...

    _onRouteMatched: function(oEvent) {
        this.getView().setModel(new JSONModel({siteInfo: {}, surveyInfo: {}, categories: []}), "view");
        var oViewModel = this.getView().getModel("view");
}

However, if I'm returning to the page without refreshing (by pressing the back arrow and then returning), I'm getting a duplicate ComponentId error when creating the view again.

        var oPanel = new sap.m.Panel({
           expandable: true,
           expanded: false,
           headerText: oData.results[0].CategoryDesc,
           id: "Panel" + index
        });

It's as though the view component "Panel" still exists, so that a new one can only be created on refresh, not onRouteMatched.

This works fine if I refresh the page, but how can I get the view to refresh on onRouteMatched?

Upvotes: 0

Views: 6136

Answers (1)

Andrew Naumovich
Andrew Naumovich

Reputation: 1450

Simply avoid programmatical controls creation (by coding) and try to define all the stuff right it the XML view and make use of bindings - it's a very powerfull feature that can solve 99% of your problems. You define binding once and change the view only via data modifications in the model, but not via the DOM manipulation (bindings will do it for free based on the model state).

I'd recommed you to go throught the data binding tutorials in the official documentation.

As for your problem, if to imagine the solution without bindings, you should always destroy the stuff manually and recreate it again. Or perform some existence checks.

Upvotes: 2

Related Questions