gpt4 book ai didi

node.js - Node_redis hgetall 回调函数上的 Coffeescript 变量范围

转载 作者:太空宇宙 更新时间:2023-11-04 02:42:20 26 4
gpt4 key购买 nike

我有以下代码:

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 调用回调将其作为参数传递给函数?

弗雷德

最佳答案

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

`@leagueId = userLeagueId`

然后在getLeagueInfo内引用@leagueId

关于node.js - Node_redis hgetall 回调函数上的 Coffeescript 变量范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13152517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com