【问题标题】:Cannot go back to default templates in meteor无法返回流星中的默认模板
【发布时间】:2016-11-01 22:24:51
【问题描述】:

所以我在一个 html 页面中使用了 4 个模板。模板 1 是默认模板,无论何时访问此 html 页面,您都应该看到它。

但是,当我浏览其他模板和其他 html 页面后,当我返回此页面时,它会显示我离开该页面时所在的模板,而不是默认模板。

HTML:

<template name = "Page1">
  <div class = "events">
    {{>Template.dynamic template=selector}}
  </div>
</template>

<template name = "template1">...</template>
<template name = "template2">...</template>
<template name = "template3">...</template>
<template name = "template4">...</template>

Javascript:

if(Meteor.isClient) {
  Session.setDefault("selector","eventDetailPage");

  Template.showEvent.helpers ({
    selector: function () {
      return Session.get("selector");
    }
  });

  Template.showEvent.events ({
   'click #temp2': function(){
        Session.set('selector’,'template2')
    }
  });

  ...template 2, 3, 4...
}

【问题讨论】:

  • showEvent 模板在哪里?

标签: javascript html templates meteor


【解决方案1】:

Session.setDefault("selector","eventDetailPage"); 大概是您用来跟踪渲染了哪个模板1/模板2/...。它只会在使用网络浏览器初始化时被调用。

如果您想在每次返回 page1 时都返回默认页面,您将需要类似的内容。

Template.Page1.onRendered(function() {
    `Session.set("selector","template1");`
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    • 2014-02-13
    • 1970-01-01
    • 2016-08-21
    • 2013-05-11
    • 2022-10-23
    相关资源
    最近更新 更多