Deleting a view and onclick opening it again, as if it is new - SAPUI5

1.2k Views Asked by At

I have a multiple View setup, a main View and then modules who are opened on button click after certain actions.

Right now the view is reset by me whenever its opened, but what I want to accomplish is, when the view is left, that its gone from the core and its initiated again as if it is opened for the first time.

I am not certain how, and I tried multiple things, none worked as I intended (.destroy(), .removeAllContent(), ... ).

Did I miss a function or is there a way to accomplish that?

Some code:

index.js (how the View is instantiated the first time, its not called a second time)

module.exports.Partner = function(place) {
    View = require('./app/js/suche.view');
    Bearbeiten = require('./app/js/bearbeiten.view');
    var ctrl = View.getController();
    ctrl.setPlace(ctrl, place);
    ctrl.setEditPlace(ctrl, place);
    ctrl.setCreatePlace(ctrl, place);
    sap.ui.getCore().byId('suche').placeAt(place);
    sap.ui.getCore().byId('suche').byId('searchBtn').attachPress(ctrl.nummerSearch, ctrl);
};

controller (how the View and the index.js is called)

handlePartnerSuche : function(){
        this.hideView(); //this is the main view
        var p = require('bit-js-business-partner');
        var partner_view = p.Partner('content');
        p.setCallbackForSchliessen(this, this.callbackForSchliessen);
  },

controller (callback function)

callbackForSchliessen: function(){
        this.showView();
    },

The second View (how its closed)

handleSchliessen : function () {
        var p = this.getView('suche');
        p.setVisible(false);

        this.callbackMethodSchliessen.call(this.callbackCtrlSchliessen);
    },
1

There are 1 best solutions below

1
On BEST ANSWER

You mentioned you cannot use the Router mechanism due to company restrictions -- am really curious to know what these restriction are then ;-) -- and toggle the visibility properties of the respective views instead.

In that case, I would trigger the OData service in the method where you set the view's visibility to visible, and (re)bind the ODataModel to that view.

From a performance perspective, I would not advise to destroy views from the core