0

我没有找到解决这个问题的方法。我目前正在使用CRUD Master-Detail Application WebIDE模板,并通过OData调用添加了一些自定义函数。使用模拟服务器运行应用程序时,它会加载模拟数据。到目前为止,一切都很好。但是如果我向模拟服务器发送一个读取请求throws a 404 not found error

请求网址

https://webidetesting[...].dispatcher.hana.ondemand.com/here/goes/your/serviceurl/MyEntity(12345)

这是我index文件中的模拟服务器部分flpSandboxMockServer.html

<script>
        sap.ui.getCore().attachInit(function() {

            sap.ui.require([
                "my/project/localService/mockserver"
            ], function (mockserver) {
                // set up test service for local testing
                mockserver.init();

                // initialize the ushell sandbox component
                sap.ushell.Container.createRenderer().placeAt("content");
            });
        });
    </script>

OData 读取调用如下所示:

onRemoveMyEntityBtnPress: function () {
        let oEntityTable = this.byId("lineItemsList");
        let aSelectedItems = oEntityTable.getSelectedItems();
        let oModel = this.getModel();

        for (let oSelectedItem of aSelectedItems) {
            let sBindingPath = oSelectedItem.getBindingContext().getPath();
            let sGuid = this._selectGuidFromPath(sBindingPath);

            this._loadEntityFromService(sGuid, oModel).then((oData) => {
                // Next step: change a property value
            }).catch((oError) => {
                jQuery.sap.log.error(oError);
            });
        }

        if (oModel.hasPendingChanges()) {
            oModel.submitChanges();
        }
    },
_loadEntityFromService: function (sGuid, oModel) {
        return new Promise((resolve, reject) => {
            oModel.read(`/MyEntity(${sGuid})`, { 
                success: (oData) => {
                    resolve(oData);
                },
                error: (oError) => { // call always ends up here with 404 error
                    reject(oError);
                }
            });
        });
    },

有人知道我还需要做什么才能将我的读取请求发送到模拟服务吗?

4

1 回答 1

1

终于找到解决办法了!我使用 OData 实体类型来读取我的实体。我将目标更改为我的实体集,现在它不会引发 404 错误。

于 2018-08-10T08:48:33.397 回答