Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor:单击后在模板内渲染模板_Javascript_Templates_Meteor_Modal Dialog_Bootstrap Modal - Fatal编程技术网

Javascript Meteor:单击后在模板内渲染模板

Javascript 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

我有一个Meteor应用程序,它加载了一个模板。 在模板里面我有一个按钮。 单击按钮时,我希望应用程序渲染或切换到另一个模板,这也恰好是一个模式

我不知道如何通过单击事件函数呈现另一个模板

有什么想法吗?下面是我的代码

search.html

<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);
    }
);