Javascript Meteor:单击后在模板内渲染模板
我有一个Meteor应用程序,它加载了一个模板。 在模板里面我有一个按钮。 单击按钮时,我希望应用程序渲染或切换到另一个模板,这也恰好是一个模式 我不知道如何通过单击事件函数呈现另一个模板 有什么想法吗?下面是我的代码 search.htmlJavascript Meteor:单击后在模板内渲染模板,javascript,templates,meteor,modal-dialog,bootstrap-modal,Javascript,Templates,Meteor,Modal Dialog,Bootstrap Modal,我有一个Meteor应用程序,它加载了一个模板。 在模板里面我有一个按钮。 单击按钮时,我希望应用程序渲染或切换到另一个模板,这也恰好是一个模式 我不知道如何通过单击事件函数呈现另一个模板 有什么想法吗?下面是我的代码 search.html <template name='search'> <button class='btn btn-primary' id='showModalButton'>Show Modal</button> </t
<template name='search'>
<button class='btn btn-primary' id='showModalButton'>Show Modal</button>
</template>
<template name='searchCustomer'>
<!-- set up the modal to start hidden and fade in and out -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal title</h4>
</div>
<!-- dialog body -->
<div class="modal-body">
My modal body
<div class="modal-footer"><button type="button" class="btn btn-primary">OK</button></div>
</div>
</div>
</div>
</template>
我还没有尝试过这一点,但我相信您可以使用模板助手和会话变量来实现这一点
<body>
{{> search }}
{{#if showModal }}
{{> searchCustomer }}
{{/if}}
</body>
searchCustomer模板仅在“showModal”会话变量为true时呈现
<body>
{{> search }}
{{#if showModal }}
{{> searchCustomer }}
{{/if}}
</body>
Template.search.helpers({
'showModal': function(){
return Session.get('showModal');
}
'click #showModalButton': function(){
Session.set('showModal', true);
}
);