【问题标题】:Meteor: helper variable not refreshingMeteor:辅助变量不刷新
【发布时间】:2016-01-30 13:14:41
【问题描述】:

在流星信使应用程序中,我为您正在与之交谈的每个用户提供页面。但是当你切换用户时,它并不总是切换对话。

辅助变量似乎没有刷新。有什么想法吗?

Router.route('/cc/:name',{ 
      template: "cc",
      name: "cc",
      data: function(){
        var x = //...
        chat = Chats.find({users: {$all: [x, Meteor.userId()]}});
      }
    });

帮手

Template.cc.helpers({
    'chat': function(){
        return chat
    }
});

模板

<template name="cc">
 {{#each chat}}
    {{#each message}}
        <span>{{senderName}}</span>
        <b>{{content}}</b>
    {{/each}}
    </div>
 {{/each}}
</template>

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    它不是反应式的,因为分配不是反应式操作。助手有反应式上下文Chats.find 是一个反应式数据源,但你必须从反应式数据源 中读取 strong> reactive context 使其具有响应性。

    解决方案 A

    它看起来像一个 IronRouter,所以直接从 Router 传递数据。阅读更多here

    解决方案 B

    chat 变成ReactiveVar。阅读更多here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      相关资源
      最近更新 更多