Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.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 使用flow router Meteor在模式中打开singlePost.\u id页_Javascript_Meteor_Meteor Blaze_Flow Router - Fatal编程技术网

Javascript 使用flow router Meteor在模式中打开singlePost.\u id页

Javascript 使用flow router Meteor在模式中打开singlePost.\u id页,javascript,meteor,meteor-blaze,flow-router,Javascript,Meteor,Meteor Blaze,Flow Router,我已经创建了路由和patFor,以便能够访问mysite.com/post/id,但我不想在新页面中打开它,而是希望它在一个模式中打开,并且找不到如何使用meteor和flow router来完成 我目前链接到postId页面的方式是使用meteor add arillo:flow router helpers软件包: <a href="{{pathFor '/post/:id' id=_id}}">Link to post</a> 但这将带我到我的singlePo

我已经创建了路由和patFor,以便能够访问mysite.com/post/id,但我不想在新页面中打开它,而是希望它在一个模式中打开,并且找不到如何使用meteor和flow router来完成

我目前链接到postId页面的方式是使用meteor add arillo:flow router helpers软件包:

<a href="{{pathFor '/post/:id' id=_id}}">Link to post</a>

但这将带我到我的singlePost blaze模板…我希望该模板以模式打开,而不是作为新页面…因此我将其更改为:

<template name="spotPage">


<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        {{#if Template.subscriptionsReady}}
            {{#with thisPost}}
                <li>{{title}}</li>
                <li>{{country}}</li>

            {{/with}}
        {{else}}
            <p>Loading...</p>
        {{/if}}
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>

  </div>
</div>
</template>

&时代;
模态头
{{{#if Template.subscriptionsReady}
{{{#用这篇文章}
  • {{title}}
  • {{国家}
  • {{/与}} {{else} 加载

    {{/if} 接近
    但是我如何用模式及其数据上下文切换特定的post.\u id


    谢谢在启动模式之前,请使用会话变量设置postId,然后在模板帮助程序中检索postId。

    要将变量传递给模式,只需在模板中传递参数:

    例如,如果您有一个名为“myModalTemplate”的模式模板,并且希望向其传递一个变量myVar,该变量应包含父模板上可用的变量“variable”

    你可以称之为

    {{>myModalTemplate myVar=variable}}
    
    然后单击打开模式,并在

    Template.myModalTemplate.helpers({
         'myVariable': function() { return this.myVar; } 
    })
    

    (实际上,您应该能够使用模式模板中的myVar直接访问它)

    以下是我的问题的答案,从其他资源中找到的:

    <template name="listOfItems">
      {{#each item}}
        <a href="#" class="item-link" data-id="{{_id}}" />{{title}}</a>
      {{/each}}
    </template>
    
    <template name="viewItemModal">
      <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        {{#if Template.subscriptionsReady}}
            <li>{{title}}</li>
            <li>{{country}}</li>
        {{else}}
            <p>Loading...</p>
        {{/if}}
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
    </template>
    
    Template.listOfItems.events({
      'click .item-link': function(e,t){
        e.preventDefault();
        var itemId = e.currentTarget.dataset.id;
        var item = Items.findOne({_id:itemId});
        var title = item.title;
        var country = item.country;
        Modal.show('viewItemModal', {title:title, country:country});
      }
    });
    
    
    {{{#每项}
    {{/每个}}
    &时代;
    模态头
    {{{#if Template.subscriptionsReady}
    
  • {{title}}
  • {{国家}
  • {{else} 加载

    {{/if} 接近 Template.listOfItems.events({ “单击项目链接”:函数(e,t){ e、 预防默认值(); var itemId=e.currentTarget.dataset.id; var item=Items.findOne({u id:itemId}); var title=item.title; var国家=项目国家/地区; show('viewItemModal',{title:title,country:country}); } });

    另外,这是我用来将参数传递给模式的…

    对不起,我不明白…现在我正在使用一个帮助程序返回特定的post/postId=Template.postPage.helpers({thisPost:function(){//从集合中获取路由参数id var id=FlowRouter.getParam('id'));var post=Posts.findOne({//使用给定id从集合中获取所选条目数据。_id:id})|{};return post;});但是我不明白如何链接到它,使它在模式中打开…在我使用只有一行链接到它的包之前链接到它,模式没有路径,所以你需要调用一个启动模式的函数,而不是
    {{pathFor'/post/:id'id=\u id}
    。如果您能提供更多提示,您可以执行
    launchPostModal(id)
    操作,但仍有困难,将有帮助…我不知道如何获取特定帖子的Id…我有1000篇帖子,因此每次在launchmodal函数中都必须提供要渲染的特定帖子..完全丢失了Hahas使用post
    \u Id
    应用函数,就像您在这里做的那样:
    {{pathFor'/post/:Id'Id=\u Id}
    ,除了使用
    launchPostModal>之外(_id)