0
votes

I'm stuck with my little UI5 app. It's a master/detail app with the according 2 views. I want to get access to the selected data set inside the detail controller. The view and the app itself work. I can display the data inside the detail view.

But I need the data in the controller. I spent hours reading and I'm sure it must be very simple.

Inside the detail controller in the handleRouteMatched I defined a new variable var dataObject = this.getView().bindObject(oPath);

When I debug the dataObject I see that the data is there (but all data not just the selected). It's deep inside the "undefined" Chrome Debugger Picture

Chrome Debugger 2 And I have no clue how to get hold of this. Can someone help?

EDIT:

var sContext = this.getView().oController.sContext; //Retrieve context
var oModel = this.getOwnerComponent().getModel(); // Aquire the model
console.log(oModel.getProperty("/" + sContext + "/Businesstravel"));

That's how I finally got it working. It would have been nice to get the whole record though (not only single fields).

1

1 Answers

1
votes
  1. get the object where you have binded the context.
  2. get this context, and get the path from it.
  3. get the corresponsing data from your model using the path

something like this:

var oView = this.getView().byId('DetailPage1');
var sPath = oView.getBindingContext('myModelName').getPath();
var myData = this.getView().getModel('myModelName').getProperty(sPath);

EDIT

Well I didn't follow all your code, but tested two things that will help you.

First, to get the parameters in your route I use in your detailPage1 Controller

onInit: function(){
this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this.oRouter.getRoute("DetailPage1").attachPatternMatched(this._onObjectMatched, this);
...
},

_onObjectMatched: function(oEvent) {
  var contextFromRouterParameter = oEvent.getParameter("arguments").context;
  console.log('contextFromRouterParameter: ' + contextFromRouterParameter);
},

Second, to get your model (you defined it in the manifest, so it is set in the component level) you need to do:

var oModel = this.getOwnerComponent().getModel();

Wherever you wnat to retrieve it. Then you can use its functions like: getProperty(sPath) as I mentioned before