Reputation: 300
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"
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).
Upvotes: 0
Views: 1650
Reputation: 2265
something like this:
var oView = this.getView().byId('DetailPage1');
var sPath = oView.getBindingContext('myModelName').getPath();
var myData = this.getView().getModel('myModelName').getProperty(sPath);
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
Upvotes: 1