使用Edm.DateTime作为主键的一部分执行OData方法 [英] Performing OData methods with Edm.DateTime as part of primary keys

查看:154
本文介绍了使用Edm.DateTime作为主键的一部分执行OData方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我想通过HTTP请求更新表.但是我总是在表中的Edm.DateTime属性上收到错误消息.

I have the problem, that I want to update a table via HTTP-request. But I always get an error-message on the Edm.DateTime attributes in the table.

错误:无效的URI段'00:00',ValdTo = datetime'2019-04-03T00:00:00')'}}

Error: Invalid URI-Segment '00:00',ValdTo=datetime'2019-04-03T00:00:00')'"}

即使该值已经转换为Edm.DateTime.

Even the value is already converted to Edm.DateTime.

valdfrom_edit = encodeURI(sap.ui.model.odata.ODataUtils.formatValue(new Date(values.ValdFrom), "Edm.DateTime"));
var update = "/ZSCORDERINGSet(Mandt='010',Vkorg='" + vkorg_Edit + "',ZzscSpSas='" + suppl_edit + "',ValdFrom=" + valdfrom_edit + ",ValdTo=" + valdto_edit + ")";

推荐答案

尝试

const myODataModel = this.getOwnerComponent().getModel(/*modelName*/);
const update = () => myODataModel.update("/" + myODataModel.createKey("ZSCORDERINGSet", {
  //<key>s for ZSCORDERING as described in $metadata
  Mandt: "010",
  Vkorg: vkorg_Edit,
  ZzscSpSas: suppl_edit,
  ValdFrom: new Date(values.ValdFrom), // no need to use ODataUtils.
  ValdTo: valdto_edit
}), {
  // properties of the entry that should be updated
}, {
  // additional parameters such as success-, error-handler, groupId, ...
});
myODataModel.metadataLoaded().then(update);

API参考:v2.ODataModel#update

关于API createKey,请参见如何可以在UI5中动态创建实体路径吗?它将根据OData规范并始终以正确的顺序为您创建实体路径.

About the API createKey, see How to Create Entity Path Dynamically in UI5? It will create the entity path for you according to the OData specification and always in the right order.

除此之外,请记住, MockServer不支持Edm.DateTime.

Apart from that, please keep in mind that MockServer doesn't support Edm.DateTime in keys.

Edm.DateTime键:不支持

这篇关于使用Edm.DateTime作为主键的一部分执行OData方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆