Search code examples
javascriptsapui5

create a control with same Id after destroying it


I have destroyed a control view and i want to create it with same Id. How to achieve that?

       var sheetNumber = this.getView().byId("shtNum");
       sheetNumber.destroy();

       if(!sheetNumber){
          var sheetView = new sap.ui.xmlview({
                id:"shtNum",
                viewName:"com.prowess.view.PieceId"
          });
        this.createId(sheetView);
      }

but it is showing sheetView is undefined. Thanks in Advance


Solution

  • I believe that you need to delete the instance of the control

       var sheetNumber = this.getView().byId("shtNum");
       sheetNumber.destroy();
       delete sheetNumber;
    
       if (!sheetNumber) {
          var sheetView = new sap.ui.xmlview({
            id:"shtNum",
            viewName:"com.prowess.view.PieceId"
          });
        this.createId(sheetView);
      }