我有一些像这样的代码
def lookupTickets() {
User currentUser = webAuthService.currentUser()
def http = new HTTPBuilder(zdURL)
http.auth.basic("${zdUser}/token", zdApiKey)
http.get(path: "/api/v2/users/search.json",
query: [query: currentUser.emailAddress],
requestContentType: ContentType.JSON, { resp, json ->
println "Response status: ${resp.statusLine}"
def zenDeskUserId = json?.users[0]?.id
})
return MYRESULT
}
第def zenDeskUserId = json?.users[0]?.id
行给了我想要返回浏览器的结果。
如果只在内部闭包内的范围内,我怎么能在外部方法中返回这个值?
答案 0 :(得分:2)
你觉得这不行吗?
def lookupTickets() {
def zenDeskUserId
User currentUser = webAuthService.currentUser()
def http = new HTTPBuilder(zdURL)
http.auth.basic("${zdUser}/token", zdApiKey)
http.get(path: "/api/v2/users/search.json",
query: [query: currentUser.emailAddress],
requestContentType: ContentType.JSON, { resp, json ->
println "Response status: ${resp.statusLine}"
zenDeskUserId = json?.users[0]?.id
})
return zenDeskUserId
}