簡體   English   中英

SAPUI5和OData服務的動態URL

[英]SAPUI5 and dynamic URL for OData service

我正在使用sapui5做示例示例。 我想動態傳遞URL服務並加載ODATA服務,但我確實是sapui5的新手,但我不知道該怎么做。 下面的代碼是我嘗試執行的操作,但無法正常工作。 非常感謝你的幫助。

createContent : function(oController) {
    var oLayout = new sap.ui.commons.layout.AbsoluteLayout({width:"340px",height:"150px"});
    oLayout.addStyleClass("CustomStyle"); //Add some additional styling for the border


    var oLabel = new sap.ui.commons.Label({text:"Service Url"});
    var oUrlInput = new sap.ui.commons.TextField({width:"190px"});
    oLabel.setLabelFor(oUrlInput);
    oLayout.addContent(oLabel, {right:"248px",top:"20px"});
    oLayout.addContent(oUrlInput, {left:"110px",top:"20px"});


var oLabel = new sap.ui.commons.Label({text:"Service"});
    var oSvcInput = new sap.ui.commons.TextField({width:"190px"});
    oLabel.setLabelFor(oSvcInput);
    oLayout.addContent(oLabel, {right:"248px",top:"62px"});
    oLayout.addContent(oSvcInput, {left:"110px",top:"62px"});

    var loadData =new sap.ui.commons.Button({
        text : "load",
        width:"133px",
     press: function() {
                 oController.load();
                  }});

    oLayout.addContent(loadData, {left:"110px",top:"104px"});


    return oLayout;
}

//控制器

load: function(oEvent){


    var url = sap.ui.getControl("oUrlInput").getValue();
    var svc = sap.ui.getControl("oSvcInput").getValue();

    var oModel = new sap.ui.model.odata.OdataModel(url + "/" + svc ,false);
    var mylist = new sap.ui.model.ListBinding(oModel);
     return mylist;




}

// index.html

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>


        <script src="resources/sap-ui-core.js"
                id="sap-ui-bootstrap"
                data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.ux3"
                data-sap-ui-theme="sap_bluecrystal">
        </script>
        <!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs' if required -->

        <script>
                sap.ui.localResources("simpleform");
                var view = sap.ui.view({id:"idsimpleForm1", viewName:"simpleform.simpleForm", type:sap.ui.core.mvc.ViewType.JS});
                view.placeAt("content");
        </script>

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

您必須為控件提供一個ID,才能在控制器中訪問它們。 像這樣:

// create controls with id
var oLabel = new sap.ui.commons.Label("oLabelId", {text:"Service Url"});
var oUrlInput = new sap.ui.commons.TextField("oUrlInputId", {width:"190px"});

// then to get reference to the control later
var oLabel = sap.ui.getCore().byId("oLabelId");
var oUrlInput = sap.ui.getCore().byId("oUrlInputId");

確保使用正確的網址:

var oModel = new sap.ui.model.odata.OdataModel("/sap/opu/odata/sap/" + svc ,false);

確保遵循。

  1. 將odataModel的大小寫更改為ODataModel
  2. 確保服務網址也正確
  3. 獲取控件的參考如kjokinen所述

問候

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM