【发布时间】:2017-04-10 10:09:20
【问题描述】:
我正在尝试使用闭包从我的服务器路径(我使用 rpc 作为 API)返回原始 JSON,因为我想将其保留在同一个函数中,而不是使用 .then() 并调用另一个函数。
这是我的代码:
GetEntryDiscussionsFromDb(){
var url = "http://localhost:8082/discussionApi/v1/getAllDiscussions";
getRawJson(String response){
return response;
}
HttpRequest.getString(url).then(getRawJson);
return getRawJson;
}
然后在我的主要功能中我这样做:
var getRawJson = GetEntryDiscussionsFromDb();
print(getRawJson());
这样做我得到这个错误:
G.GetEntryDiscussionsFromDb(...).call$0 is not a function
我用错了闭包吗?有没有办法在 .then() 中返回实际的原始 Json 而不是调用另一个函数?
提前致谢
【问题讨论】: