我想使用自定义标头来提供有关响应数据的更多信息。是否有可能通过对象存储(dojo 1.7)将dojo datagrid的响应中的头部连接到jsonRest对象?我在看到XHR请求时发现这是possible,但在这种情况下,它是由网格生成的。Dojo datagrid jsonrest响应标头
的API provides为返回的响应对象的响应错误事件:
on(this.grid, 'FetchError', function (response, req) {
var header = response.xhr.getAllResponseHeaders();
});
使用这个我能够成功访问我的自定义响应头。但是,当请求成功时,似乎没有办法获取响应对象。我一直使用undocumented私人活动_onFetchComplete纵横后,但是,这并没有允许访问响应对象,只是响应值
aspect.after(this.grid, '_onFetchComplete', function (response, request)
{
///unable to get headers, response is the returned values
}, true);
编辑: 我设法得到的东西的工作,但我怀疑它是非常过分的设计和一个更好的理解的人可以拿出一个更简单的解决方案。我最后添加了方面,让我能够在返回到对象存储的其余存储中获取延迟对象。在这里,我添加了一个新的函数来返回头文件。然后我使用dojo hitch连接到对象存储的onFetch(因为我需要当前范围中的结果)。这似乎对我来说很混乱
aspect.around(restStore, "query", function (original) {
return function (method, args) {
var def = original.call(this, method, args);
def.headers = deferred1.then(function() {
var hd = def.ioArgs.xhr.getResponseHeader("myHeader");
return hd;
});
return def;
};
});
aspect.after(objectStore, 'onFetch', lang.hitch(this, function (response) {
response.headers.then(lang.hitch(this, function (evt) {
var headerResult = evt;
}));
}), true);
有没有更好的方法?
这将在标准json商店:var results = this.inherited(arguments); (function(){ var headers = results.ioArgs.xhr.getResponseHeader('my-header'); }); –