Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Iron路由器和Meteor加载数据_Javascript_Meteor_Iron Router - Fatal编程技术网

Javascript 使用Iron路由器和Meteor加载数据

Javascript 使用Iron路由器和Meteor加载数据,javascript,meteor,iron-router,Javascript,Meteor,Iron Router,这是我的困境。我目前正在使用静态变量将我的类别加载到“类别”页面。所有内容都会加载,链接都可以单击,但当用户单击该类别时。“categoryPage”不会加载属于该类别的相应图像。这是我的密码 类别页面HTML: <template name="categoryPage"> <div class="text-center light-container" id="home-section"> <h1>{{categoryName}}&l

这是我的困境。我目前正在使用静态变量将我的类别加载到“类别”页面。所有内容都会加载,链接都可以单击,但当用户单击该类别时。“categoryPage”不会加载属于该类别的相应图像。这是我的密码

类别页面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>
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} });
    }
});
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
});
路由器JS:

<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>
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} });
    }
});
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”:函数()中,更改

与:

以下是工作代码: