2016-04-25 61 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是一个很好的起点,以了解更多有关...