0

我有一些这样的代码

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给了我想要返回浏览器的结果。

当它仅在内部闭包内的范围内时,如何在外部方法中返回此值?

4

1 回答 1

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
}
于 2013-08-23T22:30:34.360 回答