我正在尝试在 Dojo 中组织我的代码,但我不了解事情是如何工作的。我想在 REST 调用后捕获 json 数据,但它不起作用。我分配 REST 返回的testJson属性始终为 NULL。
我怎样才能做到这一点?我在下面复制了我当前的代码。(我想在 ClassDAO 和 Controller 中使用我的代码。
define([
'dojo/_base/declare',
'dojo/request/xhr'
], function (declare, xhr) {
return declare(null, {
testJson: null,
constructor: function(){
},
get: function(){
xhr('/rest/reports', {
method: 'get',
handleAs: 'json',
headers: {
Accept: 'application/json'
}
}).then(function(jsonData){
testJson = jsonData;
}, function(err){
alert(err);
}, function(evt){
// Handle a progress event from the request if the
// browser supports XHR2
});
}
});
});