onAfterAction
在数据到达之前运行两次,之后运行一次。为什么在数据到达之前运行?此外,在此基本版本中,rendered
在数据到达后调用,但在我的应用程序中,它在数据到达之前被调用。知道为什么会这样吗?基本复制:
https://github.com/lorensr/waiton-bug
Items = new Meteor.Collection 'items'
Router.configure
waitOn: ->
Meteor.subscribe 'items'
if Meteor.isServer
Meteor.publish 'items', ->
Items.find {}
Router.route '/',
name: 'hello'
答案 0 :(得分:1)
您没有定义loadingTemplate
。如果您没有加载模板,Iron Router就无法使用加载模板,因此效果会忽略waitOn
的等待效果。
只需添加loadingTemplate即可。
onAfterAction
一次又一次地运行。第一个是等待时,另一个是有反应性变化或数据准备就绪。如果您想要不这样做,请改用onRun
。
答案 1 :(得分:0)
您告诉路由器收集订阅的内容。集合和订阅都是响应数据源。因此,当该集合发生更改时,waitOn将填充并更新包含onAfterAction的路径。