文档不会仅显示在第一页上

时间:2017-09-26 13:35:27

标签: javascript pagination meteor-blaze subscriptions

我遇到这种奇怪的情况,我无法弄清楚问题是什么。有一个集合的分页,在导航时工作正常。我在一个集合中有5个文档,每个文档在页面上每2个显示分页。每个文档都有一个URL链接,单击该链接时会显示该文档的完整页面。现在的挑战是,如果我单击第一页上的文档,它将显示完整记录,但如果我导航到下一页并单击文档,则会显示一个空白页面。我尽我所能,但没有得到正确的东西。请帮忙。

这些早期帖子是对现有帖子的构建:Publish and subscribe to a single object Meteor jsMeteor js custom pagination

这是帮手

singleSchool: function () {
  if (Meteor.userId()) {
     let myslug = FlowRouter.getParam('myslug');
       var subValues = Meteor.subscribe('SingleSchool', myslug );
       if (myslug ) {
       let Schools = SchoolDb.findOne({slug: myslug});
       if (Schools && subValues.ready()) {
          return Schools;
       }
    }
  }
},

这是火焰模板

<template name="view">
  {{#if currentUser}}
    {{#if Template.subscriptionsReady }}
      {{#with singleSchool}}
        {{singleSchool._id}}
        {{singleSchool.addschoolname}}
      {{/with}}
    {{/if}}
  {{/if}}
</template>

1 个答案:

答案 0 :(得分:0)

试试这个;

onCreated功能:

Template.view.helpers({
    singleSchool(){
        if (Meteor.userId()) {
            let school = SchoolDb.findOne({slug: Template.instance().dynamicSlug.get()});
            if (school) {
              return school;
            }
        }
    }
});

<强>辅助

    <form action="admin/signup/" method="post">
    <div class="form-horizontal form-label-left">

                {% csrf_token %}
                {% for field in signupForm %}
                <p>
                    {{ field.label_tag }}<br>
                    {{ field }}
                    {% if field.help_text %}
                    <small style="color: grey">{{ field.help_text }}</small>
                    {% endif %}
                    {% for error in field.errors %}
                    <p style="color: red">{{ error }}</p>
                    {% endfor %}
                </p>
                {% endfor %}

                <div class="ln_solid"></div>
                <div class="form-group">
                  <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-4">
                    <button class="btn btn-primary">Cancel</button>
                    <button type="submit" class="btn btn-success">Submit</button>
                  </div>
                </div>
              </div>
              </form>