0

我正在使用 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>
4

3 回答 3

0

确保您使用正确的 URL:

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

于 2014-11-28T13:18:23.153 回答
0

确保遵循。

  1. 将odataModel的大小写改为ODataModel
  2. 确保服务 URL 也正确
  3. 获取控件的引用如kjokinen所述

问候

于 2014-12-24T13:13:13.727 回答
0

你必须给你的控件一个 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");
于 2014-11-25T08:41:00.923 回答