使用Iron Router和Meteor加载数据 [英] Loading data using Iron Router and Meteor

查看:82
本文介绍了使用Iron Router和Meteor加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的难题.我目前正在使用静态变量将类别加载到类别"页面上.一切都会加载,并且链接是可单击的,但是当用户单击类别时. "categoryPage"不会加载属于该类别的相应图像.这是我的代码.

Here is my dilemma. I'm currently loading my categories using a static variable onto the 'category' page. Everything loads and the links are clickable but when a user clicks on the category. The 'categoryPage' won't load the respective images that belong to that category. Here is my code.

类别页面HTML:

<template name="categoryPage">
    <div class="text-center light-container" id="home-section">
        <h1>{{categoryName}}</h1>
        <hr/>
        <div class="row">
            {{#each categoryGifs}}
                <a href="{{pathFor 'gif'}}">
                    <img class="freezeframe gifs" data-id="{{_id}}" src="{{image}}"/>
                </a>
            {{/each}}
        </div>
    </div>
</template>

类别页面JS:

Template.categoryPage.helpers({
    // Load 16 most recent ones
    // When down arrow is click load another 16 more gifs
    'categoryName': function(){
        var category = this.params.category;
        return category;
    },
    'categoryGifs': function() {
        var category = this.params.category;
        console.log(category);
        return GifsCollection.find({category: category}, {fields: {_id: 1, image: 1, category: 1} });
    }
});

路由器JS:

Router.route('/categories', {
    name: 'categories',
    template: 'categories',
    fastRender: true
});
Router.route('/categories/:category', {
    name: 'categoryPage',
    template: 'categoryPage',
    data: function(){
        var category = this.params.category;
        return GifsCollection.find({category: category});
    },
    fastRender: true
});

推荐答案

在'categoryGifs'中:function(),change

in 'categoryGifs': function(), change

    var category = this.params.category;

具有:

    var category = Router.current().params.category;

这是工作代码:

http://meteorpad.com/pad/AdRS8mfyHsZjA2Rvp/Leaderboard

这篇关于使用Iron Router和Meteor加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆