SAP UI5 ODataModel.createEntry 单步调试

简介: SAP UI5 ODataModel.createEntry 单步调试

方法入口:


initOData: function(){
         function mySuccessHandler(){
            debugger;
         }
         function myErrorHandler(){
            debugger;
         }
         var oModel = new ODataModel("http://localhost:8089/Northwind/Northwind.svc/");
         var oMetadata = oModel.getServiceMetadata();
         var result = oModel.getProperty("/Customer('ALFKI')/Address");
  var oContext = oModel.createEntry("/Customers", {
            properties : {Name : "Laptop X", Description:"New Laptop", Price:"1000", CurrencyCode : "USD"}
         debugger;

第一个参数为 entitySet 名称,第二个参数为待创建的 entry payload:




需要在 metadata 加载完毕之后,才能调用 createEntry 方法。




修改之后的代码:


sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/model/json/JSONModel",
    "sap/ui/model/resource/ResourceModel",
    "sap/ui/model/odata/v2/ODataModel"
 ], function (UIComponent, JSONModel, ResourceModel,ODataModel) {
    "use strict";
    return UIComponent.extend("sap.ui5.walkthrough.Component", {
       metadata : {
          "interfaces": ["sap.ui.core.IAsyncContentCreation"],
          "rootView": {
             "viewName": "sap.ui5.walkthrough.view.App",
             "type": "XML",
             "id": "app"
          }
       },
       initOData: function(){
         function mySuccessHandler(){
            debugger;
         }
         function myErrorHandler(){
            debugger;
         }
         function myLoaded(oEvent){
            debugger;
            var oContext = oModel.createEntry("/Customers", {
            properties : {Name : "Laptop X", Description:"New Laptop", Price:"1000", CurrencyCode : "USD"}});
            oModel.submitChanges({success: mySuccessHandler, error: myErrorHandler});
        // handle successful creation or reset
        oContext.created().then(
          function () { /* successful creation */ },
          function () { /* deletion of the created entity before it is persisted */ }
        );
         }
         var oModel = new ODataModel("http://localhost:8089/Northwind/Northwind.svc/");
         var oData = {
            name:'Jerry'
         };
         oModel.attachMetadataLoaded(oData, myLoaded);
         var oMetadata = oModel.getServiceMetadata();
         var result = oModel.getProperty("/Customer('ALFKI')/Address");
         debugger;
        // bind a form against the transient context for the newly created entity
        // oForm.setBindingContext(oContext);
        // submit the changes: creates entity in the back end
       },
       init : function () {
          UIComponent.prototype.init.apply(this, arguments);
          this.initOData();
          var oData = {
             recipient : {
                name : "SAP UI5 初学者教程之九 - 创建第一个 Component"
             }
          };
          var oModel = new JSONModel(oData);
          this.setModel(oModel);
          var i18nModel = new ResourceModel({
             bundleName: "sap.ui5.walkthrough.i18n.i18n"
          });
          this.setModel(i18nModel, "i18n");
       }
    });
 });


现在 metadata 处于成功加载状态,执行 create 函数:



得到 entityType:




this.mChangeGroups 里有一个默认的 change group:



使用默认的 changes group:




生成一个 dummy 的 uid?



submit change:



执行异步队列:




这个 batch 请求什么时候生成的?



HTTP 202 状态码代表的意思是 请求已被接受,但尚未处理,即 HTTP 202 Accepted 响应状态。


这个状态码表明客户端发起的请求,可能会被服务器端处理,也可能会被拒绝,适用于异步操作场合,允许服务器接受其他过程请求,而不用让客户端一直保持与服务器的连接直至批处理操作全部完成。


使用 Postman 给 Northwind 发送 HTTP post 请求创建 customers 的 script:





url:https://services.odata.org/V2/Northwind/Northwind.svc/$batch


content-type:multipart/mixed;boundary=batch_23c4-3627-5005


body:


--batch_23c4-3627-5005
Content-Type: multipart/mixed; boundary=changeset_6ddc-5df2-c1a1
--changeset_6ddc-5df2-c1a1
Content-Type: application/http
Content-Transfer-Encoding: binary
POST Customers HTTP/1.1
Content-Type: application/json
Content-ID: id-1664894186776-9
sap-contextid-accept: header
Accept: application/json
Accept-Language: en-US
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
Content-Length: 130
{"Name":"Laptop X","Description":"New Laptop","Price":"1000","CurrencyCode":"USD","__metadata":{"type":"NorthwindModel.Customer"}}
--changeset_6ddc-5df2-c1a1--
--batch_23c4-3627-5005--


发送之后,收到 HTTP 202 Accepted 的响应:




相关文章
|
4月前
|
前端开发 搜索推荐 开发者
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
SAP UI5 sap.m.Column 控件的 minScreenWidth 属性介绍
|
4月前
|
JavaScript 前端开发 开发者
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
SAP UI5 控件 sap.m.ListBase 的 inset 属性的作用介绍
|
4月前
|
Web App开发 数据采集 前端开发
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
纯技术讨论:如何让 SAP UI5 应用无法被别人在浏览器里调试 - 这种做法不推荐试读版
|
4月前
|
存储 安全 测试技术
使用 Visual Studio Code 创建 SAP UI5 项目遇到 self-signed security certificate 相关问题
使用 Visual Studio Code 创建 SAP UI5 项目遇到 self-signed security certificate 相关问题
什么是 SAP ABAP 里的 Subscreen
什么是 SAP ABAP 里的 Subscreen
什么是 SAP ABAP 里的 Subscreen
|
4月前
|
开发者 UED
关于 SAP UI5 sap.m.Column 的 demandPopin 属性
关于 SAP UI5 sap.m.Column 的 demandPopin 属性
SAP UI5 Link 控件的使用方法介绍 - 后续学习 Fiori Elements Smart Link 的基础试读版
SAP UI5 Link 控件的使用方法介绍 - 后续学习 Fiori Elements Smart Link 的基础试读版
|
4月前
|
安全 开发者
如何在 SAP ERP 系统调试 Product Initial Download
如何在 SAP ERP 系统调试 Product Initial Download
|
4月前
|
中间件
如何在 SAP CRM 系统调试 Product Initial Download
如何在 SAP CRM 系统调试 Product Initial Download
|
4月前
|
XML 存储 数据格式
SAP UI5 控件 customData 属性的应用介绍
SAP UI5 控件 customData 属性的应用介绍
下一篇
云函数