SAPUI5使用CDN - 404错误

时间:2016-01-12 16:51:42

标签: cdn sapui5

我使用SAPUI5开发了一个表单,并决定尝试从本地资源(即UI5库)切换到使用CDN。我一开始就收到404错误,详细说明如下。谁能告诉我为什么以及如何纠正这个问题?

的index.html

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='X-UA-Compatible' content='IE=edge' />
    <title>Vendor Accreditation - Purchaser's Information &amp; Justification</title>

    <!--src="https://openui5.hana.ondemand.com/1.32.8/resources/sap-ui-core.js"app/resources/sap-ui-core.js-->
    <script id='sap-ui-bootstrap'
            type="text/javascript"
            src='https://openui5.hana.ondemand.com/1.32.8/resources/sap-ui-core.js'
            data-sap-ui-theme='sap_bluecrystal'
            data-sap-ui-libs='sap.m'
            data-sap-ui-compatVersion='edge'
            data-sap-ui-preload='async'>
    </script>

    <script>
        jQuery.sap.registerModulePath('views', 'app/views/');
        jQuery.sap.registerModulePath('controllers', 'app/controllers/');

        sap.ui.getCore().attachInit(function () {
            new sap.m.Shell({
                app: new sap.ui.xmlview({
                    viewName: "views.Form1"
                })
            }).placeAt("content");
        });
    </script>

</head>
<body class='sapUiBody'>
    <div id='content'></div>
</body>
</html>

Form1.view.xml

<mvc:View
    controllerName="controllers.Form1"
    xmlns="sap.m"
    xmlns:core="sap.ui.core"
    xmlns:mvc="ap.ui.core.mvc"
    displayBlock="true">
    <app>
        <pages>
            <Page title="Section 1 - PURCHASER'S Information and Justification" showFooter="true">
                <Panel headerText="1.1 Requestor">
                    <InputListItem label="Name:">
                        <Input value=""></Input>
                    </InputListItem>
                </Panel>

                    <Panel headerText="1.2 Vendor">
                    <List>
                        <InputListItem label="Title:">
                            <Input value="{/title}"></Input>
                        </InputListItem>
                        <InputListItem label="Name:">
                                <Input value="{/name}"></Input>
                        </InputListItem>
                        <InputListItem label="Street:">
                                <Input value="{/street}"></Input>
                        </InputListItem>
                        <InputListItem label="City:">
                            <Input value="{/city}"></Input>
                        </InputListItem>
                        <InputListItem label="State:">
                            <Input value="{/state}"></Input>
                        </InputListItem>
                        <InputListItem label="ZIP Code:">
                            <Input value="{/zipcode}"></Input>
                        </InputListItem>
                        <InputListItem label="Country:">
                            <Input value="{/country}"></Input>
                        </InputListItem>
                        <InputListItem label="Phone:">
                                <Input value="{/phone}" type="Phone"></Input>
                        </InputListItem>
                        <InputListItem label="Email:">
                                <Input value="{/email}" type="Email"></Input>
                        </InputListItem>

                    </List>
                </Panel>
                <Panel>
                    <Toolbar>
                        <ToolbarSpacer/>
                        <Button text="submit" type="Accept" press="onSubmit"></Button>
                        <ToolbarSpacer/>
                        <Button text="cancel" type="Reject" press="onCancel"></Button>
                        <ToolbarSpacer/>
                    </Toolbar>
                </Panel>

            </Page>
        </pages>
    </app>
</mvc:View>

Form1.controller.js

sap.ui.define([
   "sap/ui/core/mvc/Controller",
   "sap/ui/model/json/JSONModel",
   "sap/m/MessageToast",
   "sap/ui/model/odata/ODataModel"//,"sap/ui/model/odata/v2/ODataModel"
], function (Controller, JSONModel, MessageToast, ODataModel) {
    "use strict";
    return Controller.extend("controllers.Form1", {

        onInit: function () {
            /*
            var model = {
                title: 'Company'
            };
            model = new JSONModel(model);
            this.getView().setModel(model);
            */

            //var oModel = new ODataModel("https:/<server name removed>/sap/opu/odata/sap/zvendorint/", true);

            /*
            var oModel = new ODataModel("https://<server name removed>/sap/opu/odata/sap/zvendorint/", undefined, true);
            sap.ui.getCore().setModel(oModel, "myModel");
            this.getView().setModel(oModel);

            oModel.setHeaders(
            {
                "X-Requested-With": "XMLHttpRequest",
                "X-CSRF-Token": "Fetch"
            });

            oModel.read("/ZVendorIntSet('')", undefined, [parseInt(Math.random() * 100000)], false,
                function (oData, response) {
                    var data = OData;
                },
                function (oError) {
                    alert('Error occurred!');
                }

            );
            */
        },

        onSubmit: function () {
            MessageToast.show("Submitted!");

            var oModel = sap.ui.getCore().getModel("myModel");

            data.Title = "Company";
            data.Name = "Michael Freake";

            oModel.setHeaders(
            {
                "X-Requested-With": "X",
                "X-CSRF-Token": "Fetch"
            });
            oModel.create("/ZVendorIntSet", data, null, {
                function(oData, response) {
                    alert("Successfully saved to SAP");
                },
                function(oError) {
                    alert("Error saving data to SAP");
                }
            });
        },

        onCancel: function () {
            MessageToast.show("Cancelled!");
        }


    });
});

错误 enter image description here

项目结构 *请注意,当我在index.html文件中使用以下脚本时,一切正常。

<script id='sap-ui-bootstrap'
        type="text/javascript"
        src='app/resources/sap-ui-core.js'
        data-sap-ui-theme='sap_bluecrystal'
        data-sap-ui-libs='sap.m'
        data-sap-ui-compatVersion='edge'
        data-sap-ui-preload='async'>
</script>

enter image description here

1 个答案:

答案 0 :(得分:0)

看来你有一个类型......在你的 Form1.view.xml 中用app取代app(我的意思是控制标签)。然后它应该工作。这也不适用于你当地的ui5 ......