单击时,模板数据需要在同一页面中呈现

时间:2015-10-28 06:48:39

标签: javascript html meteor meteor-helper

我正在尝试渲染数据(来自模板),例如隐藏(当单击后退按钮时)并在同一HTML页面上显示(当单击视图按钮时)。我的代码如下:

<h2>Saved Deals</h2>
<p>This includes deals which are in draft</p>
<p><a class="btn btn-black fjalla" id="viewsaveddeals" role="button">View »</a>{{> saveddeals}}</p>

1 个答案:

答案 0 :(得分:0)

您可以使用Meteor Sessions,例如:

if (Meteor.isClient) {
    Template.deals.helpers({
        showSavedDeals: function () {
            return Session.equals('showSavedDeals', true);
        }
    });
    Template.deals.events({
        'click #viewsaveddeals': function () {
            Session.set('showSavedDeals', true);
        }
    });
    Template.deals.onDestroyed(function () {
        Session.set('showSavedDeals', null);
    });
}
<template name="deals">
    <h2>Deals<span>12</span></h2>

    <p>This includes deals which are in draft</p>

    <p><a class="btn btn-black fjalla" id="viewsaveddeals" role="button">View
        »</a>{{#if showSavedDeals}}{{> saveddeals}}{{/if}}</p>
</template>

<template name="saveddeals">
    <h2>Saved deals</h2>
</template>