1

我有以下代码:

genUserLeagueDiscussionTable = (userLeagueId, firstEntry, displayEntries) ->
  # Generate League Discussion
  leagueDiscussionTable = 
    striped:   yes
    bordered:  yes
    hover:     no
    condensed: yes
    columns:   [{head:"Name"}, {head:"Comments"}]

  console.log "get userLeague #{userLeagueId}"
  LeagueId = userLeagueId

  getLeagueDiscussionEntries =  (entry, callback) =>
    getDiscussionEntry = (err,cnreply) ->
      setDiscussionTableRows = (err,replyObj,request) ->
        leagueDiscussionTable.rows[entry.dataentrynum].data = [replyObj.nickname,cnReply.entryText]
      console.log "Reply received for entry ",entry.entrynum
      console.log cnreply.entryText
      loginclient.hgetall 'uid:'+cnReply.postingUid, setDiscussionTableRows
      callback()
    lookupentry = entry.lookupentry
    console.log "getting entry for ", entry, " database key ", lookupentry
    leagueclient.hgetall lookupentry, getDiscussionEntry
  getLeagueInfo = (err,lreplyObj) =>
    console.log "got league info", lreplyObj
    leagueDiscussionTable.caption = lreplyObj.leagueName+" League Info"
    console.log "caption", leagueDiscussionTable.caption
    leagueDiscussionEntries = lreplyObj.currentDiscussionEntry
    console.log "Caption ",leagueDiscussionTable.caption," entries ", leagueDiscussionEntries, " Display Entries ",displayEntries
    lastEntry = Math.min(leagueDiscussionEntries,firstEntry+displayEntries)
    console.log "start entry ", firstEntry, " last entry ", lastEntry
    entries=[]
    for num in [firstEntry..lastEntry]
      console.log num,".a"
      entries[num]={}
      entries[num].entrynum=num
      console.log num,".b"
      entries[num].lookupentry="userLeagueId:#{LeagueID}:discussionEntryId:#{entry}"
      console.log num,".c"
      entries[num].dataentrynum = num-firstEntry
      console.log num," ", entries[num]
    console.log "Lookup the entries ", entries
    async.forEach entries, getLeagueDiscussionEntries
    , (err,reply) ->
      console.log "callback 1"
  leagueclient.hgetall "userLeagueId:#{LeagueId}", getLeagueInfo
  return leagueDiscussionTable

无论我做什么,我都无法在 getLeagueInfo 中访问 LeagueId 或 userLeagueId。它在外部包装器中工作正常,但我无法在回调函数中访问它。

我究竟做错了什么?

谢谢您的帮助。

[编辑] 有没有办法通过对回调的 hgetall 调用将它作为参数传递给函数?

弗雷德

4

1 回答 1

0

您的代码有很多依赖项,因此很难单独理解,但我建议更改LeagueId为实例变量:

`@leagueId = userLeagueId`

然后@leagueIdgetLeagueInfo.

于 2012-10-31T15:48:59.503 回答