JayData - 从HTTP Patch读取响应

时间:2014-08-25 16:03:38

标签: odata jaydata

我正在尝试使用JayData进行PATCH调用后,从基于ODataController的服务对我的客户端JavaSript对象应用一些更改。在发出PATCH请求后如何查看HTTP响应(200)?我不知道JayData API在哪里公开响应。我的代码看起来像这样:

var deferred = $q.defer();
self.context.ready.then(function (cxt) {
    myAwesomeEntity.entityState = $data.EntityState.Modified;
    cxt.myAwesomeEntitys.attach(myAwesomeEntity, true);

    // HACK update the TimeStamp reference to trick JayData into including it in the HTTP PATCH request.
    var temp = myAwesomeEntity.Timestamp;
    myAwesomeEntity.Timestamp = [];
    myAwesomeEntity.Timestamp = temp;

    cxt.saveChanges().then(function (data) {
        deferred.resolve(data); // Shouldn't data be the HTTP Patch response?  It's actually "3".
    }, function (error) {
        //Handle error here...
    });
});

return deferred.promise;

HTTP Patch(200)响应类似于:

{
    "odata.metadata": "http://localhost:21171/odata/$metadata#MyAwesomeEntity/@Element",
    "odata.type": "MyNamespace.MyAwesomeEntity",
    "odata.id": "http://localhost:21171/odata/MyAwesomeEntity(guid'14812a96-8da1-4202-b8c7-a5697774ae4b')",
    "SomeCollection@odata.navigationLinkUrl": "http://localhost:21171/odata/MyAwesomeEntity(guid'14812a96-8da1-4202-b8c7-a5697774ae4b')/SomeCollection",
    "Timestamp@odata.type": "Edm.Binary",
    "Timestamp": "AAAAAAJxWhg="
}

1 个答案:

答案 0 :(得分:0)

JayData oDataProvider返回受影响的项目数。我修改它以返回修改的实际项目。