【问题标题】:Pagination with alethes:pages using a subscriptionalethes 分页:使用订阅的页面
【发布时间】:2015-09-06 03:04:03
【问题描述】:

伙计们。我在 Meteor 应用程序中使用alethes:pages 进行分页,并且我需要使用现有订阅来控制它显示的数据。它的工作方式似乎只是对集合中的所有记录进行分页,而不是我想要显示的特定内容。

到目前为止我得到的代码是这样的,定义了分页:

BrowsePages = new Meteor.Pagination(Mods, {
    perPage: 15,
    sort: {
        createdAt: -1
    },
    templateName: "browseModsList",
    itemTemplate: "browseModItem",
    table: {
        fields: ["name", "category", "createdAt"],
        header: ["Name", "Author", "Category", "Date Added", "Rating", "Current Version"],
        class: "table table-striped"
    },
    divWrapper: false,
    auth: function(skip, sub) {
        var theCat = Categories.findOne({slug: Router.current().params.slug});
        return Mods.find({category: theCat._id});
    }
});

我假设它会将分页数据限制在我通过 auth 返回的光标,但现在它只是用微调器挂在那里。

我很困惑,任何能对此有所了解的人都会很棒。我希望在分页上(以某种方式)强制执行相同的限制,我只是不知道该怎么做。

这里是更相关的代码:

路线:

// Browse
Router.route('/browse/:slug', function() {
    this.render('browseModsList');
}, {
    name: 'browse',
    waitOn: function() {
        return [
            Subs.subscribe('catMods', this.params.slug)
        ]
    }
});

出版

Meteor.publish('catMods', function(tag) {
    var category = Categories.findOne({slug: tag});
    if (category) {
        var catId = category._id;
        return Mods.find({category: catId});
    } else {
        return this.ready();
    }
});

像往常一样提前感谢您的帮助!

【问题讨论】:

    标签: javascript node.js meteor pagination


    【解决方案1】:

    如下所示添加字段键。

    BrowsePages = new Meteor.Pagination(Mods, {
    
        perPage: 15,
        fields: {name: 1, category:1, createdAt:1},
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多