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,
can you check what object is the returned from oEvent.getSource(). If it is a table, please use following code:
let oItem = oEvent.getParameter("listItem");
let oCtx = oItem.getBindingContext("myModel")
Best Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
the sap.m.Table (coming from sap.m.ListBase) does have the event itemPress which you created a handler for. This means that the Table does fire the event and is thus the source.
You can get the item from the listItem parameter of the event.
However, you can also add a handler for the press event of any listitem: https://sapui5.hana.ondemand.com/#/api/sap.m.ListItemBase%23events/press
In this handler the call of oEvent.getSource() would give you the listitem.
Regards
Nils
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 |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.