关于 SAP UI5 ODataModel.createEntry 返回的 context 对象

在返回的上下文中使用创建的 API 返回的 Promise 对象,以便在持久化或重置时获得通知。使用 isTransient API,您可以确定创建的上下文是 transient 的还是持久的;请注意,对于尚未在客户端创建但已从后端读取的上下文,API 返回 undefined。

Transient 上下文通常用于绑定表单或弹出窗口,以便最终用户可以查看或修改已创建条目的数据,然后再将其持久化到后端。上下文的数据根据​​创建请求成功的响应进行更新。请注意,Transient 上下文的路径包含客户端生成的 UID 作为临时键谓词,例如产品集(‘id-1641815139894-99’)。在应用程序编码中使用此路径时要小心,因为一旦上下文被持久化,它就会变得无效;然后上下文根据持久实体的规范 URL 更改其路径,例如到产品集(‘4711’)。

下面的所有实体创建示例都假设模型以批处理模式运行,即使用 useBatch = true 构建。

看个具体的例子:

// create an entry in the Products collection with the specified properties and values as initial data
var oContext = oModel.createEntry("/ProductSet", {
    properties : {Name : "Laptop X", Description:"New Laptop", Price:"1000", CurrencyCode : "USD"}
});
// bind a form against the transient context for the newly created entity
oForm.setBindingContext(oContext);
 
// submit the changes: creates entity in the back end
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 */ }
);
 
// delete the created entity by resetting the corresponding change
oModel.resetChanges([oContext.getPath()], undefined, /*bDeleteCreatedEntities*/true);

createEntry 方法采用可选的 refreshAfterChange 参数,该参数确定在后端创建成功后是否刷新所有受影响的绑定。

此参数用于在创建后更新与新实体的列表绑定,使其显示在绑定的表控件中。

在需要进行此类更新的情况下,我们建议使用下面描述的 ODataListBinding#create API 而不是 ODataModel#createEntry。

相关文章

学习编程是顺着互联网的发展潮流,是一件好事。新手如何学习...
IT行业是什么工作做什么?IT行业的工作有:产品策划类、页面...
女生学Java好就业吗?女生适合学Java编程吗?目前有不少女生...
Can’t connect to local MySQL server through socket \'/v...
oracle基本命令 一、登录操作 1.管理员登录 # 管理员登录 ...
一、背景 因为项目中需要通北京网络,所以需要连vpn,但是服...