2016-04-25 65 views
-2

使用路由時,我無法將我的上下文綁定到sap.m.table。在SplitApp,當我點擊主頁面線項目,採用SAPUI5使用上下文路由顯示沒有數據

contextarg = decodeURIComponent(evt.getParameter("arguments").ctx);

現在我瀏覽到詳細信息頁面和上下文,我已經過了使用

var url = "***/sap/opu/odata/SAP/ZFIRST_VENDOR_SRV"; 
    var olineOdataModel = new sap.ui.model.odata.ODataModel(url,false); 
    var rd = contextarg+ "/VENDORITEMSSet"; 
    olineOdataModel.read(rd, 
       null, 
       null, 
       false, 
       function(oData, oResponse){ 

       var oODataJSONModel = new sap.ui.model.json.JSONModel();           
       oODataJSONModel.setData(oData); 
       // store the model 
       var lineTable = sap.ui.getCore().byId("__xmlview5--lineItemTable");     
       lineTable.setModel(oODataJSONModel,"localModel"); 
       console.log(lineTable.getModel("localModel")); 

控制檯這個參數去OData的顯示輸出作爲

enter image description here

,我已經照

與表結合
<Table id="lineItemTable" headerText="Line Items" items="{'/results'}"> 
     <columns> 
      <Column> 
       <header> 
        <Label text="Product ID" /> 
       </header> 
      </Column> 
      <Column> 
       <header> 
        <Label text="Product Name" /> 
       </header> 
      </Column> 
      <Column> 
       <header> 
        <Label text="Product Price" /> 
       </header> 
      </Column> 
      <Column> 
       <header> 
        <Label text="Product Weight (gms)" /> 
       </header> 
      </Column> 
      <Column> 
       <header> 
        <Label text="Available From" /> 
       </header> 
      </Column> 
     </columns> 
     <ColumnListItem> 
      <cells> 
       <ObjectIdentifier title="{ProductId}" /> 
       <ObjectIdentifier title="{ProductName}" /> 
       <ObjectIdentifier title="{ProductPrc}" /> 
       <ObjectIdentifier title="{ProductWt}" /> 
       <ObjectIdentifier title="{AvailableFrom}" /> 
      </cells> 
     </ColumnListItem> 
    </Table> 

但是我在視圖中沒有數據。我試過items="{'results'}"items="{path:'results'}"。請幫助。我在這裏做了什麼錯誤?!

回答

1

更改綁定到以下幾點:

items="{'localModel>/results'}" 

正如你所看到的別名添加您的命名模式。然後還加了別名,你正在使用的模板命名模式:

<ColumnListItem> 
    <cells> 
     <ObjectIdentifier title="{localModel>ProductId}" /> 
     <ObjectIdentifier title="{localModel>ProductName}" /> 
     <ObjectIdentifier title="{localModel>ProductPrc}" /> 
     <ObjectIdentifier title="{localModel>ProductWt}" /> 
     <ObjectIdentifier title="{localModel>AvailableFrom}" /> 
    </cells> 
</ColumnListItem> 

而不是做這一切的,你可以只使用,而不是

lineTable.setModel(oODataJSONModel); 
console.log(lineTable.getModel()); 

lineTable.setModel(oODataJSONModel,"localModel"); 
console.log(lineTable.getModel("localModel")); 

提示: 您正在創建ODataModel以基本執行AJAX請求。讓組件實例化ODataModel將是一種更好的方法,以便在UI5中使用OData + ODataModel的功能。 Walkthrough Tutorial是一個很好的起點,以瞭解更多有關...