2016-04-28 89 views
5

我正在致力於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"); 

名單顯示,但是當我選擇該項目錯誤拋出。

回答

5

​​,獲取給定模型名稱的該對象的綁定上下文。如果對象沒有綁定上下文,並且沒有自己的模型集,它將使用在其父層次結構中定義的第一個綁定上下文。

您已爲模型命名(this.setModel(oModel,"data");)。 指定型號名稱(oItem.getBindingContext('data')),而訪問綁定上下文

+0

它工作正常。 :) – FEBzX

+0

@FEBzX,很高興幫助你:) – Rayon

3

嘗試:

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

你要通過模型來「getBindingContext()」的名稱,如果綁定模型已被命名。