getBindingContext() 返回未定义 [英] getBindingContext() returns undefined

查看:59
本文介绍了getBindingContext() 返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 SplitApp.从列表中选择一个项目时,它说

I am working on a SplitApp. On selecting an item from the list, it says

未捕获的类型错误:无法读取未定义的属性getPath"

Uncaught TypeError: Cannot read property 'getPath' of undefined

Master.controller.js

onSelect: function(oEvent) {
  this.showDetail(oEvent.getParameter("listItem") || oEvent.getSource());
},

showDetail: function(oItem) {
  // ...
  this.getRouter().navTo("detail", {
    from: "master",
    entity: oItem.getBindingContext().getPath().substr(1), // Error
    tab: this.sTab
  }, bReplace);
},

oItem.getBindingContext() 返回 undefined.所以我认为问题在于绑定上下文.

oItem.getBindingContext() returns undefined. So I believe the problem is with binding context.

<List id="list" growing="true" items="{data>/results}">
  <ObjectListItem id="listItem"
    title="{myModel>PROJECTNAME}"
    number="{myModel>REVENUE}"
    numberUnit="{myModel>CURRENCY}"
    press=".onSelect"
  />
</List>

Component.js

// JSONModel required from "sap/ui/model/json/JSONModel"
var oModel= new JSONModel();
oModel.loadData("Data.json");
this.setModel(oModel,"myModel");

列表已显示,但当我选择该项目时,抛出错误.

The list is displayed but when I select the item, the error is thrown.

推荐答案

getBindingContext(sModelName?)

获取给定模型名称的此对象的绑定上下文.如果对象本身没有设置绑定上下文并且没有自己的模型集,它将使用在其父层次结构中定义的第一个绑定上下文.

您已为模型命名 (this.setModel(oModel, myModel")).指定模型名称 (oItem.getBindingContext("myModel")) 以访问绑定上下文.

You have given name to the model (this.setModel(oModel, "myModel")). Specify the model name (oItem.getBindingContext("myModel")) to access the binding context.

同样适用于 setBindingContext(oContext, "myModel").

这篇关于getBindingContext() 返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆