Gateway Odata服务不在SAP UI5中从后端返回数据

时间:2017-05-23 05:03:14

标签: sapui5

我正在尝试构建一个应用程序,我试图通过ODATA服务获取数据并尝试在SAP UI5中填充表。以下是代码

<script>    
        var oTable = new sap.ui.table.Table({
                                            title: "Outstanding Balance",
                                            visibleRowCount: 5,
                                            //firstVisibleRow: 5,
                                            selectionMode: 
                                            sap.ui.table.SelectionMode.Single

                                        });

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "CustomerID"}),
        template: new sap.ui.commons.TextField().bindProperty("value",                                             "Customer"),
    //  sortProperty: "Customer",
        //filterProperty: "Customer",
        width: "200px"
    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Name"}),
        template: new sap.ui.commons.TextField().bindProperty("value", "Name"),
        //sortProperty: "Name",
        //filterProperty: "Name",
        width: "100px"
    }));

    var oModel = new sap.ui.model.odata.ODataModel(
    "/sap/opu/odata/sap/Z_ATC_CUSTOMER_OUTSTANDING_SRV",true,"ABCD","1234");
    oTable.setModel(oModel);
    // bind path of oDataModel to table rows
        oTable.bindRows("/CUSTOMERSet");
    oTable.placeAt("content");
        //}


//  })

请帮助我,我错了。我的代码在服务器中正常运行,但表中没有填充任何数据。

1 个答案:

答案 0 :(得分:0)

你的代码使用Northwind通过Heroku代理在我这边工作,所以你的代码和绑定都没问题。

&#13;
&#13;
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv='X-UA-Compatible' content='IE=edge'>
		<meta charset="utf-8">

		<title>MVC with XmlView</title>

		<!-- Load UI5, select "blue crystal" theme and the "sap.m" control library -->
		<script id='sap-ui-bootstrap'
			src='https://sapui5.hana.ondemand.com/resources/sap-ui-core.js'
			data-sap-ui-theme='sap_bluecrystal'
			data-sap-ui-libs='sap.ui.table, sap.ui.commons'
			data-sap-ui-xx-bindingSyntax='complex'></script>


		<!-- DEFINE RE-USE COMPONENTS - NORMALLY DONE IN SEPARATE FILES -->

		<!-- define a new (simple) View type as an XmlView
		 - using data binding for the Button text
		 - binding a controller method to the Button's "press" event
		 - also mixing in some plain HTML
		 note: typically this would be a standalone file -->

		<script id="view1" type="sapui5/xmlview">
		
        </script>


		<script>          
          
          var oTable = new sap.ui.table.Table({
                                            title: "Outstanding Balance",
                                            visibleRowCount: 5,
                                            //firstVisibleRow: 5,
                                            selectionMode: 
                                            sap.ui.table.SelectionMode.Single

                                        });

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "CustomerID"}),
        template: new sap.ui.commons.TextField().bindProperty("value","CustomerID"),
    //  sortProperty: "Customer",
        //filterProperty: "Customer",
        width: "200px"
    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Orders"}),
        template: new sap.ui.commons.TextField().bindProperty("value", "OrderID"),
        //sortProperty: "Name",
        //filterProperty: "Name",
        width: "100px"
    }));

    var oModel = new sap.ui.model.odata.ODataModel(
    "https://cors-anywhere.herokuapp.com/services.odata.org/Northwind/Northwind.svc",true,"ABCD","1234");
    oTable.setModel(oModel);
    // bind path of oDataModel to table rows
        oTable.bindRows("/Orders");
    oTable.placeAt("content");

          
		</script>
	
	</head>
	<body id='content' class='sapUiBody'>
	</body>
</html>
&#13;
&#13;
&#13;

当您在代码中对服务URL进行硬编码时,如果您正在访问服务的正确位置,请检查HTTP跟踪。

在跟踪中查找请求,在&#34;标题&#34;中获取您要访问的URL。选项卡并在新选项卡中打开它。如果那里有空数据,则问题出在Gateway / OData服务中。如果您有错误,可能是您正在访问错误的路径。查看图片

Your code with Northwind service