【问题标题】:Skeleton Meteor application not updating across tabsSkeleton Meteor 应用程序未跨选项卡更新
【发布时间】:2015-10-10 18:50:37
【问题描述】:

我在 Linux 上使用 curl | sh 命令安装了 Meteor 的新副本,并在 Windows 上使用 Meteor 客户端安装了。

当我运行以下一系列命令时:

$ meteor create testcode
$ cd testcode
$ meteor run

Meteor 启动应用程序,并给我在http://localhost:3000/ 上运行的应用程序的消息。

当我在浏览器的两个选项卡中打开页面并单击 单击我 按钮时,“您已按下按钮 Y 次”文本没有在两个标签中使用Y+1 更新,仅当前标签。点击次数不再在标签之间同步。

这是预期的行为吗?因为我记得在早期版本中通过跨选项卡同步数字看到它起作用。

也就是说,我已经在 Linux/Windows 中分别使用 Chrome 和 Firefox / Chrome 和 Internet Explorer 进行了尝试。

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

    这是不应该的。

    您可能会将其与可以使用以下方法创建的排行榜示例应用混淆:

    $ meteor create --example leaderboard my_leaderboard
    

    默认的骨架应用程序仅更改局部反应变量。
    这是source code

    它会创建一个名为 hello 的模板。

    hello 模板的标记包括对名为 counter 的帮助器的引用和一个按钮。

    <template name="hello">
      <button>Click Me</button>
      <p>You've pressed the button {{counter}} times.</p>
    </template>
    

    Sessionsession 包提供的反应式字典 (ReactiveDict),不会在浏览器选项卡之间同步。
    它在启动时设置为0,并由counter 帮助程序进行响应式访问。

    每当变量更改并触发对 DOM 的更改时,都会重新运行帮助程序。

    // counter starts at 0
    Session.setDefault('counter', 0);
    
    Template.hello.helpers({
      //rerun whenever the Session's couter value changes
      counter: function () {
        return Session.get('counter');
      }
    });
    

    每次单击按钮时,hello 模板的事件处理程序都会增加值,这会触发 counter 帮助程序的重新运行。

    Template.hello.events({
      'click button': function () {
        // increment the counter when button is clicked
        Session.set('counter', Session.get('counter') + 1);
      }
    });
    

    【讨论】:

    • 好吧,对不起,我大错特错了。
    • 好吧,这可能是新用户的常见误解。是什么让您认为它应该同步?
    • 不知何故我仍然清楚地记得在早期的演示中看到,当一个用户单击一个选项卡中的数字时,它会在另一个选项卡上更新...
    • 好吧,AFAICT,骨架应用程序一直是这种方式(甚至更少反应)since the beginning。无论如何,这可能是一个很好的常见问题解答。
    • @Kyll,我同意。已添加。
    猜你喜欢
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多