首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用flow-router Meteor模式打开singlePost._id页面

使用flow-router Meteor模式打开singlePost._id页面
EN

Stack Overflow用户
提问于 2016-01-05 01:45:05
回答 3查看 328关注 0票数 0

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

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

代码语言:javascript
复制
<a href="{{pathFor '/post/:id' id=_id}}">Link to post</a>

但这将把我带到我的singlePost blaze模板...我希望该模板在模式中打开,而不是我更改为的新page...so:

代码语言:javascript
复制
<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>

但是,如何将特定的post._id与模态及其数据上下文进行切换呢?

谢谢

EN

回答 3

Stack Overflow用户

发布于 2016-01-05 01:49:37

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

票数 0
EN

Stack Overflow用户

发布于 2016-01-05 06:41:29

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

例如,如果你有一个名为'myModalTemplate‘的模态模板,并且你想给它传递一个变量myVar,它应该包含一个在父模板上作为' variable’可用的变量

您可以用以下命令调用它

代码语言:javascript
复制
{{>myModalTemplate myVar=variable}}

然后单击打开模式,然后在

代码语言:javascript
复制
Template.myModalTemplate.helpers({
     'myVariable': function() { return this.myVar; } 
})

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

票数 0
EN

Stack Overflow用户

发布于 2016-01-05 08:26:41

这是我的问题的答案,是从另一个资源中找到的:

代码语言:javascript
复制
<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});
  }
});

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34596809

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档