我使用mizzao:user-status
包列出了在线用户。流星帮手未运行反应
请注意,下面的代码是coffeescript,它一直工作正常,特别是因为我坚持使用Blaze而不是React(我还没有找到在coffeescript中使用JSX的方法)。
除了切线,我特别在 client.coffee
有问题。 debugger
只被调用一次,当我检查其中的users_data
变量时,它显示一个空数组。很明显,至少有一部分是反应性的,因为当我继续经过断点并再次检查users_data
的值时,它是非空的。但users
帮手的返回值似乎没有改变。该功能不会重新运行。
TL;博士
如何使users
辅助方法,重新运行时users_data
改变
# ------------------
# server.coffee
# ------------------
Meteor.publish 'user_status', ->
Meteor.users.find(
{ "status.online": true },
fields: {}
)
# ------------------
# client.coffee
# ------------------
Meteor.subscribe 'online_users'
users = Template.users
users.helpers
users: ->
window.users_cursor = Meteor.users.find
"status.online": true
window.users_data = users_cursor.collection._docs._map
debugger
window.final = Object.keys(users_data).map (_id) =>
user = users_data[_id]
{
_id,
name: user.profile.name
}
final
和火焰模板的相关部分:
<body>
<h1>Welcome to Meteor!</h1>
{{> loginButtons }}
{{> users}}
</body>
<template name="users">
{{#each users}}
<li>{{_id}}</li>
{{/each}}
</template>
更确切地说,它是周围的其他方式:['each'(HTTP:// blazejs .org/api/spacebars.html#Each)Blaze模板标签需要Meteor集合游标,但它也可以是普通数组。 – ghybs