on 09-22-2022 1:16 PM
Hi!
On my journey to learning SAP UI5 I stumbled upon these resources SAP uploaded on their Youtube channel and I gave the tutorial a try to learn some new techniques.
In the Routing & Navigation episode, I encountered an issue.
I've set everything to get the data from an external source, and created the model in the manifest.json file:
"sap.ui5":{
...
"models":{
...
"myModel":{
"dataSource":"myModelAPI"
}
}
}
Then I can access and view this data in my XML view: *this is working
<mvc:View
controllerName="myApp.controller.myController"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core">
<Table id="myTable"
items="{myModel>/}"
itemPress=".onItemPressed"
fixedLayout="false">
<columns>
...
</columns>
<items>
<ColumnListItem type="Active">
<cells>
<Text text="{myModel>id}"/>
<Text text="{myModel>name}"/>
...
</cells>
</ColumnListItem>
</items>
</Table>
</mvc:View><br>
Now, in my controller when I try to access the item clicked and send the id of the clicked item with the navTo() method and onto the next page, I get undefined from my getBindingContext() method even if I provide the name of my model in it:
sap.ui.define(
["myApp/controller/BaseController"],
function(
BaseController
) {
"use strict"
return BaseController.extend(
"myApp.controller.myController", {
onInit: function() {
let oRouter = this.getRouter()
oRouter
.getRoute("myRoute")
.attachMatched(this._onRouteMatched, this)
},
onItemPressed: function(oEvent) {
let oItem = oEvent.getSource()
let oCtx = oItem.getBindingContext("myModel")
console.log(oCtx) // always undefined
}
}
)
}
)<br>
What is wrong with above or what am I doing wrong? Hopefully I've provided enough context so you can tell.
Thanks!
Hi,
check this out:
https://sapui5.hana.ondemand.com/#/api/sap.m.ListBase%23events/itemPress
Regards,
Radoslaw
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.