Meteor 卡在加载模板上
嘿,我有一个系统,一个登录的用户可以在一个“战斗”中,一旦他们,我希望用户被锁定在一个给定的模板上,直到战斗结束 我有Meteor 卡在加载模板上,meteor,Meteor,嘿,我有一个系统,一个登录的用户可以在一个“战斗”中,一旦他们,我希望用户被锁定在一个给定的模板上,直到战斗结束 我有 # # Currently active battle # Meteor.publish 'activeBattle', -> character = Characters.findOne(userId: this.userId) if this.userId and character return Battles.find({active: true,
#
# Currently active battle
#
Meteor.publish 'activeBattle', ->
character = Characters.findOne(userId: this.userId)
if this.userId and character
return Battles.find({active: true, $or: [{characterOneId: character._id}, {characterTwoId: character._id}]})
else
return
在我的铁路由器里
Router.configure
layoutTemplate: 'layout'
loadingTemplate: 'loading'
waitOn: [
Meteor.subscribe('activeBattle')
]
...
redirectToActiveBattle = (pause) ->
battle = Battles.findOne(active: true)
if battle and Meteor.userId()
throwError('You have a battle in progress.')
Router.go('combat', {_id: battle._id})
pause()
...
Router.onBeforeAction(redirectToActiveBattle, except: ['login', 'logout', 'signup', 'combat'])
当用户登录并且有一个字符时,此操作有效,但如果没有,页面将被粘贴在加载模板上,而不是显示登录屏幕。实际上,您应该使用
This.ready()如果不希望在发布中返回任何内容,请使用code>而不是空返回。因此,正确的出版方式可能是:
Meteor.publish 'activeBattle', ->
character = Characters.findOne(userId: this.userId)
if this.userId and character
return Battles.find({active: true, $or: [{characterOneId: character._id}, {characterTwoId: character._id}]})
this.ready()
在publish
的else
子句中,尝试return[]
而不是return
。