Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2812

Bind ObjectId data to view after navigation

$
0
0

In an application of two views where navigation happens via routing with ObjectID , how can the resultant ObjectID data binded to view2.

 

Code in View2 controller:

 

onInit method:

 

onInit: function(oEvent) {          var iOriginalBusyDelay,           oViewModel = new JSONModel({           busy: true,           delay: 0           });      var oRouter = sap.ui.core.UIComponent.getRouterFor(this);     oRouter.getRoute("view2routername").attachPatternMatched(this._onObjectMatched, this);           //this.getRouter().getRoute("view2routername").attachPatternMatched(this._onObjectMatched, this);      // Store original busy indicator delay, so it can be restored later on      iOriginalBusyDelay = this.getView().getBusyIndicatorDelay();      // this.setModel(oViewModel, "objectView");      this.getOwnerComponent().getModel().metadataLoaded().then(function() {     // Restore original busy indicator delay for the object view      oViewModel.setProperty("/delay", iOriginalBusyDelay);      });     },

OnObjectMatched()

_onObjectMatched:function(oEvent) { 
var sObjectPath = "/(" + oEvent.getParameter("arguments").objectId + ")"; 
this._bindView(sObjectPath);
 },

_bindView()

_bindView: function(sObjectPath) {          var oViewModel = this.getView().getModel(),                oDataModel = this.getView().getModel();           this.getView().bindElement({                path: sObjectPath,               events: {                        change: this._onBindingChange.bind(this),                         dataRequested: function() {                          oDataModel.metadataLoaded().then(function() {
// Busy indicator on view should only be set if metadata is loaded,
// otherwise there may be two busy indications next to each other on the
// screen. This happens because route matched handler already calls '_bindView'
// while metadata is loaded.                         oViewModel.setProperty("/busy", true);                          });           },          dataReceived: function() {          oViewModel.setProperty("/busy", false);               }           }
});
},

_onBindingchange()

_onBindingChange: function(oEvent) {          var oView = this.getView(),                oViewModel = this.getView().getModel();          // No data for the binding           if (!oView.getBindingContext()) {                this.getRouter().getTargets().display("notFound");          return;
}           var oResourceBundle = this.getResourceBundle(),                oObject = oView.getBindingContext().getObject(),                sObjectId = oObject.Text,                sObjectName = oObject.No;           // Everything went fine. oViewModel.setProperty("/busy", false);                oViewModel.setProperty("/shareSendEmailSubject",                oResourceBundle.getText("shareSendEmailObjectSubject", [sObjectId]));                oViewModel.setProperty("/shareSendEmailMessage", oResourceBundle.getText("shareSendEmailObjectMessage", [sObjectName, sObjectId, location.href]));
},

The navigation from view1 to view2 works well and objectid is also being passed. But currently facing Cannot read property 'indexOf' of undefined error pointing to

_bindView() 4: this.getView().bindElement and

_onObjectMatched 3 this._bindView(sObjectPath);

 

Any suggestions?


Viewing all articles
Browse latest Browse all 2812

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>