Meteor / Blaze模板$ .Session

时间:2016-11-12 14:12:50

标签: session meteor meteor-blaze

我正在关注一个在Blaze模板中使用$ .Session.get的Meteor教程,但它没有按预期运行。模板应该评估会话变量并显示表单或按钮。如果单击该按钮,会话变量将设置为true,并且应该显示该表单。那没有发生。

我怀疑它是Meteor / Blaze版本问题,因为最近有很多变化。我正在使用Meteor 1.4.2.1,我很确定本教程适用于Meteor 1.2。

以下是模板代码段:

<template name="Recipes">
{{ #if $.Session.get newRecipe }}
  {{> NewRecipe }}
{{ else }}
  <button class="new-recipe">New Recipe</button>
{{ /if }}...

我也在使用Meteor Toys和JetSetter,并且可以看到会话变量的值为'true',因此该值是正确的。它只是没有在模板中提取它。

关于这个的任何指针?

以下是包裹清单:

meteor-base             # Packages every Meteor app needs to have
mobile-experience       # Packages for a great mobile UX
mongo                   # The database Meteor supports right now
blaze-html-templates    # Compile .html files into Meteor Blaze views
session                 # Client-side reactive dictionary for your app
jquery                  # Helpful client-side library
tracker                 # Meteor's client-side reactive programming     library

standard-minifiers      # JS/CSS minifiers run for production mode
es5-shim                # ECMAScript 5 compatibility for older browsers.
ecmascript              # Enable ECMAScript2015+ syntax in app code

kadira:flow-router
kadira:blaze-layout
erasaur:meteor-lodash
stolinski:stylus-multi
fortawesome:fontawesome
spiderable
fastclick
raix:handlebar-helpers
aldeed:collection2
aldeed:autoform
accounts-ui
accounts-password
matb33:bootstrap-glyphicons
zimme:active-route
gwendall:auth-client-callbacks
meteortoys:allthings
datariot:ganalytics
check
reactive-var

以下是相关的代码块:

// set the session var to false - hide the form, show the button
Template.NewRecipe.events({
  'click .fa-close': () => {
 Session.set('newRecipe', false);
  }
});

// set the session var to true - show the form, hide the button
Template.Recipes.events({
  'click .new-recipe': () => {
  Session.set('newRecipe', true);
  }
});

0 个答案:

没有答案