SAP UI5 - getBindingContext()undefined(splitapp)

问题描述:

我正在致力于splitappSAP UI5 - getBindingContext()undefined(splitapp)

在从列表中选择一个项目,它说

Uncaught TypeError: Cannot read property 'getPath' of undefined

Master.controller.js

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

showDetail : function(oItem) { 
      var bReplace = jQuery.device.is.phone ? false : true; 
         this.getRouter().navTo("detail", { 
          from: "master", 
          entity: oItem.getBindingContext().getPath().substr(1),      
          tab: this.sTab 
         }, bReplace); 
         } 

我绑定一个JSON Model到列表中。

oItem.getBindingContext()未定义。 所以我相信问题是绑定上下文。

在Master.view.xml列表的代码如下

<content> 
     <List 
      id="list" 
      select="onSelect" 
      mode="SingleSelect" 
      noDataText="{i18n>masterListNoDataText}" 
      growing="true" 
      growingScrollToLoad="true" 
      items="{data>/results}"> 
      <items 
       id="masterList"> 
       <ObjectListItem 
        id="listItem" 
        press="onSelect" 
        type="{device>/listItemType}" 
        counter="0" 
        title="{data>PROJECTNAME}" 
        number="{data>REVENUE}" 
        numberUnit="{data>CURRENCY}" 
        markFavorite="false" 
        markFlagged="false" 
        showMarkers="true"> 
       </ObjectListItem> 
      </items> 
     </List> 
    </content> 

我在Component.js设置如下模型:

var oModel= new sap.ui.model.json.JSONModel(); 
    oModel.loadData("Data.json"); 
    this.setModel(oModel,"data"); 

名单显示,但是当我选择该项目错误抛出。

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

您已为模型命名(this.setModel(oModel,"data");)。 指定型号名称(oItem.getBindingContext('data')),而访问绑定上下文

+0

它工作正常。 :) – FEBzX

+0

@FEBzX,很高兴帮助你:) – Rayon

尝试:

entity: oItem.getBindingContext("data").getPath().substr(1), 

你要通过模型来“getBindingContext()”的名称,如果绑定模型已被命名。