0

我已经创建了能够访问 mysite.com/post/id 的路线和 patFor,但我不想在新页面中打开它,而是希望在模式中打开它并且找不到如何使用流星和流量路由器

我链接到 postId 页面的当前方式是使用流星添加 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>

但是如何使用模态及其数据上下文切换特定的 post._id 呢?

谢谢

4

3 回答 3

0

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

于 2016-01-04T17:49:36.850 回答
0

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

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

此外,这个是我用来将参数传递给模态的......

于 2016-01-05T00:26:40.517 回答
0

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

例如,如果您有一个名为“myModalTemplate”的模态模板,并且您想将变量 myVar 传递给它,该变量应包含父模板上可用的变量“变量”

你会用它来称呼它

{{>myModalTemplate myVar=variable}}

然后单击打开模式并在

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

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

于 2016-01-04T22:41:28.547 回答