2017-01-21 4 views
-1

odata 모델을 사용하여 데이터를 바인딩하는 방법은 무엇입니까? 세그먼트 '결과'에 대해 자원을 찾을 수 없습니다. 오류가 발생합니다.테이블에 데이터 바인딩

내 코드 :.

var url = "/sap/opu/odata/sap/ZODATA_SERVICE_NAME"; 
     var oModel = new sap.ui.model.odata.ODataModel(url,false); 

      oModel.read("/EntityDataSet", null, null, true, function(oData) { 

      that.getView().setModel(oModel,"student");  
          }, 
           function(error) { 

     }); 


    <Table headerDesign="Standard" 

items="{student>/results}" 
    id="table" > 
       <columns> 
        <Column > 
         <header> 
          <Label text="studentName" width="100%"/> 
         </header> 
        </Column> 

        <Column > 
         <header> 
          <Label text="studentRank" width="100%"/> 
         </header> 
        </Column> 
       </columns> 
       <items> 
        <ColumnListItem > 
         <cells> 
          text="{student>StudentName}"/> 
          text="{student>Rank}"/> 

         </cells> 
        </ColumnListItem> 
       </items> 
      </Table> 

답변

0

that.getView()로 setModel (oModel, "학생")을 변경해보십시오; .

.getView()로 setModel (oModel, "학생")에;

0

that.getView(). setModel (oModel, "student"); // wrong

this.getView(). setModel (oModel, "student"); //이 특정 컨트롤러

2
  1. 이되지 않습니다 사용하고있는 ODataMOdel을 의미한다 ((ODataModel.read를 대신
  2. 당신이 자바 스크립트를 통해 HTTP 호출을 수행 할 필요가 없습니다 v2.ODataModel을 사용해야합니다 ...))를 사용하여 데이터를 테이블에 바인딩합니다.
  3. 나는 당신이 UI5에서 OData와 모델을 명확하게 이해하지 못했다고 생각합니다. 공식 SAPUI5 Tutorials을 보시면 도움이 될 것입니다.
  4. 어쨌든

, 여기에 running jsbin example입니다 :

<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <meta charset="utf-8"> 
 
     <title>SAPUI5 single file template | nabisoft</title> 
 
     <script 
 
     \t src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" 
 
      id="sap-ui-bootstrap" 
 
      data-sap-ui-theme="sap_bluecrystal" 
 
      data-sap-ui-libs="sap.m" 
 
      data-sap-ui-bindingSyntax="complex" 
 
      data-sap-ui-compatVersion="edge" 
 
      data-sap-ui-preload="async"></script> 
 
      <!-- use "sync" or change the code below if you have issues --> 
 

 
     <!-- XMLView --> 
 
     <script id="myXmlView" type="ui5/xmlview"> 
 
      <mvc:View 
 
       controllerName="MyController" 
 
       xmlns="sap.m" 
 
       xmlns:core="sap.ui.core" 
 
       xmlns:mvc="sap.ui.core.mvc"> 
 

 
       <Table 
 
        id="myTable" 
 
        growing="true" 
 
        growingThreshold="10" 
 
        growingScrollToLoad="true" 
 
        busyIndicatorDelay="0" 
 
        items="{/Customers('ALFKI')/Orders}"> 
 
        <headerToolbar> 
 
         <Toolbar> 
 
          <Title text="Orders of ALFKI"/> 
 
          <ToolbarSpacer/> 
 
         </Toolbar> 
 
        </headerToolbar> 
 
        <columns> 
 
         <Column> 
 
          <Text text="OrderID"/> 
 
         </Column> 
 
         <Column> 
 
          <Text text="Order Date"/> 
 
         </Column> 
 
         <Column> 
 
          <Text text="To Name"/> 
 
         </Column> 
 
         <Column> 
 
          <Text text="Ship City"/> 
 
         </Column> 
 
        </columns> 
 
        <items> 
 
         <ColumnListItem type="Active"> 
 
          <cells> 
 
           <ObjectIdentifier title="{OrderID}"/> 
 

 
           <Text 
 
            text="{ 
 
             path:'OrderDate', 
 
             type:'sap.ui.model.type.Date', 
 
             formatOptions: { 
 
             style: 'medium', 
 
             strictParsing: true 
 
             } 
 
            }"/> 
 

 
           <Text text="{ShipName}"/> 
 

 
           <Text text="{ShipCity}"/> 
 

 
          </cells> 
 
         </ColumnListItem> 
 
        </items> 
 
       </Table> 
 

 
      </mvc:View> 
 
     </script> 
 

 
     <script> 
 
      sap.ui.getCore().attachInit(function() { 
 
       "use strict"; 
 

 
       //### Controller ### 
 
       sap.ui.define([ 
 
        "sap/ui/core/mvc/Controller", 
 
        "sap/ui/model/odata/v2/ODataModel" 
 
       ], function (Controller, ODataModel) { 
 
        "use strict"; 
 

 
        return Controller.extend("MyController", { 
 
         onInit : function() { 
 
          // in component based apps you would not 
 
          // even need this piece of code: 
 
          this.getView().setModel(
 
           new ODataModel("https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/", { 
 
            json : true, 
 
            useBatch : false 
 
           }) 
 
          ); 
 
         } 
 
        }); 
 
       }); 
 

 
       //### THE APP: place the XMLView somewhere into DOM ### 
 
       sap.ui.xmlview({ 
 
        viewContent : jQuery("#myXmlView").html() 
 
       }).placeAt("content"); 
 

 
      }); 
 
     </script> 
 

 
    </head> 
 

 
    <body class="sapUiBody"> 
 
     <div id="content"></div> 
 
    </body> 
 
</html>