【问题标题】:Making if Statement reactive in Meteor在 Meteor 中使 if 语句具有反应性
【发布时间】:2016-01-06 19:36:29
【问题描述】:

我是流星新手。我开始使用会话来使内容在要使用的不同模板之间产生反应。我还在我的应用程序中使用 Ace 文本编辑器。它有一些配置设置:

Template.template_containing_AceTextEditor.configuration = function(){
      return function(editor){
                    if (Session.get('text') == "something") //here I want it to be reactive
                    {          
                       //do something every time 'text' changes
                    }
      }

}

而且我也不想丢失 Template.template_ contains_AceTextEditor.configuration,因为它连接到我正在使用的包。

【问题讨论】:

  • 你试过使用助手吗?一旦你定义了你的助手(它是反应式的),你可以在把手中使用它 {{#if something}}

标签: meteor reactive-programming ace-editor


【解决方案1】:

嗯,您可以通过多种方式使代码具有响应性,一种是将响应式代码放在Tracker.autorun 中。

Tracker.autorun(function(){
  if (Session.get('text') == "something") //this will run every time session text changes
     {          
       //do something every time 'text' changes
     }
})

确保将跟踪器加载到项目中。

【讨论】:

    猜你喜欢
    • 2015-07-18
    • 1970-01-01
    • 2020-12-20
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    相关资源
    最近更新 更多