cancel
Showing results for 
Search instead for 
Did you mean: 

getBindingContext() always returns undefined

trmt
Explorer
0 Kudos

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!

View Entire Topic
radoslaw_kiela2
Participant
0 Kudos